Reputation: 2298
I have following curl program which is working fine.
$data="var1=$var1&var2=$var2";
$ch = curl_init("http://www.website.asmx/FetchData");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
I tried following code to get same data using file_get_contents but it returns false.
$data="var1=$var1&var2=$var2";
$result = file_get_contents("http://www.website.asmx/FetchData?=".$data);
var_dump($result);
exit();
What code will be equivalent to above curl program?
Upvotes: 0
Views: 104
Reputation: 7617
Notice the = at the End of FetchData in:
$result = json_decode(file_get_contents("http://www.website.asmx/FetchData?=".$data));
This should rather read:
//WITHOUT THE EQUAL SIGN AFTER FetchData...
$result = json_decode(file_get_contents("http://www.website.asmx/FetchData?".$data));
Upvotes: 1