Sunday, 15 July 2012

web services - Javasctipt post function in to PHP function. Post to webservice -



web services - Javasctipt post function in to PHP function. Post to webservice -

i have been asked turn below javascript function in php function.

i have never been asked , have been struggling lot , may have wrong terminology in relation soap/webservices etc apologies confusion.

var varvalidationcode = "validationcode"; var email = document.getelementbyid('email').value; //alert(email); $.ajax( { url: 'http://www.domain.com/file.asmx', type: "post", data: "{email:'" + email + "',validationcode:'" + varvalidationcode + "'}", datatype: "json", contenttype: "application/json; charset=utf-8", cache: false, success: function(data) { alert(data.d); }, error: function() { alert("fail"); } }); //alert("function called successfully"); }

i tried create curl function post values below, got post on stackoverflow error - "soap:receiverserver unable process request. ---> info @ root level invalid. line 1, position 1."

// here info sending service $data = array( 'email' => 'test@test.com', 'validationcode' => 'somevalidationcode' ); $curl = curl_init('http://www.domainname.com/file.asmx'); curl_setopt($curl, curlopt_post, 1); //choosing post method curl_setopt($curl, curlopt_url, 'http://www.domainname.com/file.asmx'); // set url path want phone call curl_setopt($curl, curlopt_returntransfer, true); // create info coming set string curl_setopt($curl, curlopt_postfields, $data); // insert info // send request $result = curl_exec($curl); // free resources $curl using curl_close($curl); echo $result;

the file posting looks this:

<?xml version="1.0" encoding="utf-8"?> <soap12:envelope xmlns:xsi="htt{://www.w3.org/2001/xmlschema-instance" xmlns:xds="http://www.w3.org/2001/xmlschema" xmlns:xds="http://www.w3.org/2001/05/soap-envelope"> <soap:body> <paymentvalidationinfo xmlns="http://tempuri.org/"> <email>string</email> <validationcode>string</validationcode> </paymentvalidationinfo> <soap12:body> </soap12:envelope>

i hope makes sense. help much appreciated. regards

i'm not sure if people interested managed work how wanted working below.

$url = "http://www.domain.com/webservices/ccpwebservice.asmx/method?"; $data = array( 'email' => 'email', '&validationcode' => '4946565', ); foreach($data $key=>$value) { $content .= $key.'='.$value; } $curl = curl_init($url); curl_setopt($curl, curlopt_header, false); curl_setopt($curl, curlopt_returntransfer, true); curl_setopt($curl, curlopt_post, true); curl_setopt($curl, curlopt_postfields, $content); $json_response = curl_exec($curl); $status = curl_getinfo($curl, curlinfo_http_code); /* debug purposes if(!curl_errno($curl)) { $info = curl_getinfo($curl); echo 'took ' . $info['total_time'] . ' seconds send request ' . $info['url'].'<br/><br/>'; echo "curl error no : ".curl_errno($curl); //returns 7 echo "<br />curl status : ".curl_getinfo($curl, curlinfo_http_code); //returns 0 echo "<br />curl error : ".curl_error($curl); //returns "couldn't connect host" echo "<br />strings posted: ";print_r($content); echo "<br />curl info : ";print_r($info); }*/ curl_close($curl);

if can recommend additions/best practices much appreciated. regards

php web-services curl soap

No comments:

Post a Comment