Jump to content

CURL POST with parameters not passing parameters


JustinK101

Recommended Posts

I am calling CURL and trying to do a POST request with parameters:

 

$curl = curl_init();
curl_setopt($curl, CURLOPT_HTTPHEADER, Array("Accept: application/json", "Content-Type: application/json"));
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 15);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($curl, CURLOPT_USERAGENT, "curl 7.23.1 (x86_64-unknown-linux-gnu)");
curl_setopt($curl, CURLOPT_USERPWD, "username:password");
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_URL, "https://www.mydomain.com/route");
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, "key1=blah1&key2=blah2");
return curl_exec(curl);

 

The problem, inside the request at http://www.mydomain.com/route I am not seeing any POST parameters passed. I.E.

 

    print_r($_POST);

 

Array
(
)

 

Should have key1=blah1 and key2=blah2. Any ideas?

PHP does not parse post data unless it's content type is either a multipart/form-data or application/x-www-form-urlencoded.

 

Sending a content type of application/json doesn't seem to make any sense anyway, your post data is not a json string.  Why were you sending that header?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.