api - PHP cURL not sending POST Data -
i trying send data php rest service. seems make call correctly api doesnt send post data.
the code :
<?php $name="abcd"; $id="xyz"; $service_url = 'service/url'; $curl = curl_init($service_url); $curl_post_data = array( $name,$id); curl_setopt($curl, curlopt_returntransfer, true); curl_setopt($curl, curlopt_post, true); curl_setopt($curl, curlopt_postfields, $curl_post_data); $curl_response = curl_exec($curl); curl_close($curl); ?>
i manipulate response provided.can tell doing wrong here.
there server side validation, code :
private string validateandgetclientname(httpservletrequest request) throws invalidrequestexception { string clientname = request.getparameter("name"); if (isempty(clientname)) { throw new invalidrequestexception("client name cannot empty."); } return clientname.trim(); }
paramters in http queries make sense in associative way, if named. change definition of post data this:
$curl_post_data = array( 'name' => $name, 'id' => $id );
Comments
Post a Comment