Post json,
<?php
$ch = curl_init();
$timeout = 10; // set to zero for no timeout
$urltouse = "http://dpdev-ld03.myservercom:8181/linkmethod/signup?f=json&c=signupcallback
";
$fields_string = '{siteUrl:\"http://testurl.com\",siteRss:\"http://feeds.news.mysite.com/synfeeds/collect/6/rss.xml
\",userName:\"testuser\",email:\"testemail\",siteName:\"testsitename
\",loginId:\"testloginid\}';
curl_setopt($ch,CURLOPT_URL,$urltouse);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string); <-- shouldn't be
postfields, but some other curl option I'm guessing
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>
curl_setopt($ch,CURLOPT_POSTFIELDS,http_build_query(array("data"=>$fields_string)));
Now on the server end $_POST['data'] will contain your json data.
if you just pass the $fields_string it can be read in the server end too.
$data = file_get_contents("php://input");
now $data will contain your json data.
It completely depends on the server you are interacting with. If it
needs json in a variable then pass it using http_build_query.
Otherwise just pass json as you are doing right now.
Tidak ada komentar:
Posting Komentar