Make sure you send the query string at the end of the URL when executing the GET request.
$ qry_str = "? x = 10 & y = 20";
$ ch = curl_init ();
// Set query data here with the URL
curl_setopt ($ ch, CURLOPT_URL, 'http://example.com/test.php'. $ qry_str);
curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ ch, CURLOPT_TIMEOUT, 3);
$ content = trim (curl_exec ($ ch));
curl_close ($ ch);
print $ content;
With a POST you pass the data via the CURLOPT_POSTFIELDS option instead
of passing it in the CURLOPT__URL.
-------------------------------------------------- -----------------------
$ qry_str = "x = 10 & y = 20";
curl_setopt ($ ch, CURLOPT_URL, 'http://example.com/test.php');
curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ ch, CURLOPT_TIMEOUT, 3);
// Set request method to POST
curl_setopt ($ ch, CURLOPT_POST, 1);
// Set query data here with CURLOPT_POSTFIELDS
curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ qry_str);
$ content = trim (curl_exec ($ ch));
curl_close ($ ch);
print $ content;
Note curl_setopt() docs for CURLOPT_HTTPGET (highlighted by me):
[Set CURLOPT_HTTPGET equal] TRUE to reset the HTTP request method for GET.
Since GET is the default, this is only necessary if the request method has been changed.
RC Aug 4 '09 at 2:43 2009-08-04 02:43
source share