Posting JSON encoded data via php & cURL -


I can not send JSON encoded data via PHP; CURL

My sender code is:

  $ id = 1; $ Txt = "asdsad"; $ Txt2 = "basement"; $ Data = array ("id" = & gt; "$ id", "txt" = & gt; "$ txt", "txt2" => "$ txt2"); $ Data_string = json_encode ($ data); $ Ch = curl_init ('index.php'); Curl_setopt ($ CH, CURLOPT_CUSTOMREQUEST, "POST"); Curl_setopt ($ CH, CURLOPT_POSTFIELDS, $ data_string); Curl_setopt ($ CH, CURLOPT_RETURNTRANSFER, true); Curl_setopt ($ ch, CURLOPT_HTTPHEADER, array ('content-type: application / jason', 'content-length:'. Strlen ($ data_string)); Curl_setopt ($ ch, CURLOPT_TIMEOUT, 5); Curl_setopt ($ CH, CURLOPT_CONNECTTIMEOUT, 5); $ Result = curl_xac ($ CH); Curl_close ($ ch); $ Return result;  

index.php:

  var_dump ($ _ request);  

My revised data:

  array (0) {}  

What's the problem with my code? key = value to the data submitted at the time of creation of GET / p>

/ Post / Request Supervalals You are sending a bare string, which has no keys, no key, there is no array entry in superglows.

Try

  curl_setopt ($ ch, CURLOPT_POSTFIELDS, "foo = $ data_string"); Alternatively, since you are sending via POST, you can use  
  $ json = file_get_contents ('php: /'). / Input ');  

And just read in raw text.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -