Jump to content

CURL POST with parameters not passing parameters


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_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.






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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • 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.