JustinK101 Posted December 6, 2011 Share Posted December 6, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/252557-curl-post-with-parameters-not-passing-parameters/ Share on other sites More sharing options...
JustinK101 Posted December 6, 2011 Author Share Posted December 6, 2011 Found the issue. So the problem was that it does not like the custom header: Content-Type: application/json. When removed, it works. Any ideas why? Quote Link to comment https://forums.phpfreaks.com/topic/252557-curl-post-with-parameters-not-passing-parameters/#findComment-1294826 Share on other sites More sharing options...
kicken Posted December 6, 2011 Share Posted December 6, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/252557-curl-post-with-parameters-not-passing-parameters/#findComment-1294834 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.