How to send and receive JSON data between two servers via php -


obviously not using right keywords in searches or not understanding others have written in blogs or forums, et al.

looking information on passing data between 2 servers. data preferably contained within json array. if know of has written blog encompassing chance read it. otherwise offer thoughts?

more detailed: user visits page php function called , data "packaged up" in json array , post command other server. second server after receiving post processing , "package up" data , return in json array. user presented results.

with following receiving http 200 response. no data.

site 1:

$data_string = json_encode(array('user_id'=>123)); $ch = curl_init('http://site2.dev/retrieve'); 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/json',         'content-length: ' . strlen($data_string)         ));  $result = curl_exec($ch); $status = curl_getinfo($ch); curl_close($ch);  $result = json_decode($result);  

site 2:

public function retrieve() {     return json_encode(array('some'=>'456')); } 

the json array chosen can encrypted , yes https used in final environment.

both servers have laravel 4 php framework.

thank thoughts , comments.

add this:

curl_setopt($ch, curlopt_header, 0); 

and put quotes on content-length:

curl_setopt($ch, curlopt_httpheader,     array('content-type: application/json','"content-length: ' . strlen($data_string) . '"')); 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -