file_get_contents with GET request only passing first parameter
My servlet is using form processing with getFirstValue("value1"), getFirstValue("value2") ... etc, but all parameters after the first are null. Is there something wrong with my PHP?
$getdata = http_build_query($_GET);
$opts = array('http' =>
'method' => 'GET',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $getdata
$context = stream_context_create($opts);
$servletURL = 'http://localhost:8182';
$result = file_get_contents(servletURL, false, $context);
Have you tried to echo $getdata to see if it contains the right info?
The data it contains is this:
I was able to solve my problem by using getFirstValue("username") as usual, then for the rest of the parameters, use getFirstValue("amp;password"), getFirstValue("amp;company").
Thanks for your help. That certainly fixed my problem. Sure feels like a hack though.
You should be using "&" rather than "&" for the URL. "&" is an HTML character entity, but you are not outputting HTML, you are transmitting a HTTP request.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
I am not doing anything of the sort. The http_build_query() call is putting those amps in, and do not know how to ask it not to.
Then replace all "&" with "&" after you get the string back...doesn't have to be that difficult.
Originally Posted by DEADFA11
Or you could pass it as a serialize array in one variable and unserialize it.
That is a hack. Best to fix the input on the way out rather than create extra work on both sides of the exchange.
Originally Posted by PETTE
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)