PHP cURL JSON sending blank paramaters -


i trying send json java web service getting response web service paramaters null see below. there wrong code?

$buildapplication = array(     'firsname'          => 'keith',     'surname'           => 'francis',     'companyname'       => 'keiths mobile discos',     'phone'             => '07123456789',     'email'             => 'keith.francis@freedom-finance.co.uk',     'sourcecode'        => 'w00t' ); $data = json_encode($buildapplication);                                                                                                              $ch = curl_init('http://10.50.1.71:8080/sme/api/details.json');                                                                       curl_setopt($ch, curlopt_customrequest, "post");                                                                      curl_setopt($ch, curlopt_postfields, json_encode($data));                                                                  curl_setopt($ch, curlopt_returntransfer, true);                                                                       curl_setopt($ch, curlopt_httpheader, array(                                                                           'content-type: application/json',                                                                                 'content-length: ' . strlen($data))                                                                        );                                                                                                                 $result = curl_exec($ch); var_dump($result); 

response comes

string(1042) "{"errors":[{"object":"com.application.appdetails","field":"firstname","rejected-value":null,"message":"property [firstname] of class [class com.application.appdetails] cannot null"},{"object":"com.application.appdetails","field":"surname","rejected-value":null,"message":"property [surname] of class [class com.application.appdetails] cannot null"},{"object":"com.application.appdetails","field":"companyname","rejected-value":null,"message":"property [companyname] of class [class com.application.appdetails] cannot null"},{"object":"com.application.appdetails","field":"phone","rejected-value":null,"message":"property [phone] of class [class com.application.appdetails] cannot null"},{"object":"com.application.appdetails","field":"email","rejected-value":null,"message":"property [email] of class [class com.application.appdetails] cannot null"},{"object":"com.application.appdetails","field":"sourcecode","rejected-value":null,"message":"property [sourcecode] of class [class com.application.appdetails] cannot null"}]}" 

you have used json_encode twice.

write below line as:-

curl_setopt($ch, curlopt_postfields, $data);   

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -