Parameter Missing in XML String - php

I am passing an xml string to https://insurance-api.pingtree.co.uk/api through curl but is getting parameter error in response (code 12 0) which can be also seen if you browse the above mentioned url.The parameter is defined in the xml i.e. the campaign code then why isn't the system recognizing it. here is my code below which i also got from the http://www.quinternet.com site.
<?php
/**
* Initialize the request xml string here.
* The string in the tag like '[int]' should be replaced with actual value.
* The string in the square brackets is the data type.
*/
$request_string =
'<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:urn="urn:pt_service">
<soapenv:Header />
<soapenv:Body>
<urn:submit
soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<campaign_code>dllfYg0JBwQ</campaign_code>
<site_url>www.surelifecover.co.uk</site_url>
<client_ip>127.0.0.1</client_ip>
<policy_type>J</policy_type>
<cover_purpose>1</cover_purpose>
<cover_amount>50000</cover_amount>
<cover_term>1</cover_term>
<title>1</title>
<first_name>INTRODUCERTEST</first_name>
<last_name>wwww</last_name>
<dob >1995-04-05</dob >
<email>will#bitscube.com</email>
<home_phone>07111111111</home_phone>
<best_call_time>1</best_call_time>
<gender>F</gender>
<is_smoker>Y</is_smoker>
<title2>1</title2>
<first_name2>ww</first_name2>
<last_name2>wwww</last_name2>
<dob2>1991-02-03</dob2>
<email2>913661383#qq.com</email2>
<home_phone2>07111111112</home_phone2>
<best_call_time2>2</best_call_time2>
<gender2>M</gender2>
<is_smoker2>N</is_smoker2>
<terms_consent>Y</terms_consent>
<privacy_content>Y</privacy_consent>
<mode>LIVE</mode>
<keyword>life ins</keyword>
<match_type>1</match_type>
<network>ABC</network>
<device>mobile</device>
<ref>00</ref>
<v1>var1</v1>
<v2>var2</v2>
<v3>var3</v3>
<v4>var4</v4>
<v5>var5</v5>
<i1>1</i1>
<i2>2</i2>
<i3>3</i3>
<i4>4</i4>
<i5>5</i5>
</urn:submit>
</soapenv:Body>
</soapenv:Envelope>
</env:Envelope>';
echo htmlspecialchars($request_string);
echo '<br>';
/**
* The values of the following fields please refer
*to the reference field list spec*
//setup the request headers here, notice at the action string and SOAPAction string */
$request_headers = array('Content-Type: application/soap+xml;charset=utf-8;action="urn:pt_service#Webservice#submit"',
'SOAPAction: "urn:pt_service#Webservice#submit"',
'Content-length: '.strlen($request_string) );
//setup the service url here
$service_url = 'https://insurance-api.pingtree.co.uk/api';
//setup the user agent for the request
$user_agent = $_SERVER['HTTP_USER_AGENT'];
//initialize the curl here
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $service_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLINFO_HEADER_OUT, FALSE );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE );
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_POST,TRUE );
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_POSTFIELDS,$request_string);
curl_setopt($ch, CURLOPT_HTTPHEADER,$request_headers);
//do the submit process here
$result= curl_exec ($ch);
$response_string = curl_exec($ch);
// Convert API feed to xml object
var_dump($response_string);
$xml = simplexml_load_string($response_string);
$name = $xml->response->status;
echo $name;
//-----------------------------------------------
//parsing the response string here
/*example response below. Please get detail
refer for the reponse in specs.
<?xml version="1.0" encoding="UTF8"?>
<response>
<result>20</result>
<status>1</status>
<commission>10.00</commission>
<reference>347</reference>
<message><![CDATA[Accepted]]></message>
<redirect_url>
http://insurance-api.pingtree.co.uk/redirect?p=bUzbir4VhB-BB-Z_gMxVSy8YT15gxUB9iJMBGxi_aOq5PQuDBf_JPqgvc2egv6orCj6TJkeR5g6tX1y0D7hZgbV6DdBAlzbccKmkFNG4-PgWmaNR9LQ57cUQg6jTOXuB
</redirect_url>
</response>
//-----------------------------------------------*/
curl_close($ch);
?>

Related

Configuring soap api xml

I want to configure an api of soap with php, following the xml is used for the api, but its not responding, please help me to recover this problem
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:fram="http://framework.zend.com">
<soapenv:Header/>
<soapenv:Body>
<fram:getCountries>
<securityInfo>
<userName>username</userName>
<password>password</password>
<agentCode>code</agentCode>
<lang>en</lang>
</securityInfo>
</fram:getCountries>
</soapenv:Body>
</soapenv:Envelope>
The below showing the php code I used to call xml. But I didnt get any response to my php code, but the xml is correct, I have asked to the provider they told me the xml is correct but my php code is not correct. I dont what I do to solve this problem :(
<?php
$soapUrl = "http://testapi.roombookpro.com/en/soap/index?wsdl"; // asmx URL of WSDL
$soapUser = "username"; // username
$soapPassword = "password"; // password
// xml post structure
$xml_post_string = '<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:fram="http://framework.zend.com">
<soapenv:Header/>
<soapenv:Body>
<fram:getCountries>
<securityInfo>
<!-- You may enter the following 4 items in any order -->
<userName>username</userName>
<password>password</password>
<agentCode>agentcode</agentCode>
<lang>en</lang>
</securityInfo>
</fram:getCountries>
</soapenv:Body>
</soapenv:Envelope>'; // data from the form, e.g. some ID number
$headers = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache"
"SOAPAction: http://testapi.roombookpro.com/en/soap/index#getCountries",
"Content-length: ".strlen($xml_post_string),
); //SOAPAction: your op URL
$url = $soapUrl;
// PHP cURL for https connection with auth
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $soapUser.":".$soapPassword); // username and password - declared at the top of the doc
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// converting
$response = curl_exec($ch);
curl_close($ch);
// converting
$response1 = str_replace("<soap:Body>","",$response);
$response2 = str_replace("</soap:Body>","",$response1);
// convertingc to XML
$parser = simplexml_load_string($response2);
var_dump($parser);
echo $parser;
// user $parser to get your data out of XML response and to display it.
?>
In your code,your request is pointing to wsdl link below,
http://testapi.roombookpro.com/en/soap/index?wsdl
and thats why you are not getting soap response rather you getting the definitions.
you should use the following soap url to get the soap response,
http://testapi.roombookpro.com/en/soap/index
EDIT:
and to get the XML response (as string):
$response = curl_exec($ch);
curl_close($ch);
print_r($response);
to get as SimpleXMLElement Object :
$xml = simplexml_load_string($response);
foreach ($xml->xpath('//ns2:Soap_Model_SOAP_Location_Country') as $item)
{
print_r($item);
//to access individual elements
// echo $item->id ;
// echo $item ->code;
// echo $item->name;
// echo "\n";
}
which gives array of XML objects:
SimpleXMLElement Object
(
[id] => 252
[code] => ZW
[name] => Zimbabwe
)

PHP - Not able to read xml sub node value

I am calling this soap API with curl and not able read response value properly so can you please guide me what I am doing wrong.
Here is my code:
$wsdl = "http://xxxx/xxxx/xxxx";
$body = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:par="http://xxxx.com">
<soapenv:Header/>
<soapenv:Body>
<par:cancelReservationReq>
<par:garageID>47</par:garageID>
<par:orderNumber>orderNumber168</par:orderNumber>
<!--Optional:-->
<par:barCode>barCode168</par:barCode>
<!--Optional:-->
<par:orderTime>2015-11-19T00:30:57.905</par:orderTime>
</par:cancelReservationReq>
</soapenv:Body>
</soapenv:Envelope>';
// initializing cURL with the IPG API URL:
$ch = curl_init($wsdl);
// setting the request type to POST:
curl_setopt($ch, CURLOPT_POST, 1);
// setting the content type:
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml"));
// setting the authorization method to BASIC:
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
// filling the request body with your SOAP message:
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
// telling cURL to verify the server certificate:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
// telling cURL to return the HTTP response body as operation result
// value when calling curl_exec:
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// calling cURL and saving the SOAP response message in a variable which
// contains a string like "<SOAP-ENV:Envelope ...>...</SOAP-ENV:Envelope>":
$result = curl_exec($ch);
// loads the XML
$xml = simplexml_load_string($result);
$soapenv = $xml->children("http://schemas.xmlsoap.org/soap/envelope/");
$tns = $soapenv->Body->children("http://xxxx.com");
echo "success ".$success = $tns->cancelReservationResp->success;
echo "message ".$message = $tns->cancelReservationResp->message;
echo "garageID ".$garageID = $tns->cancelReservationResp->reservations->garageID;
API response data:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body xmlns:s="http://www.w3.org/2003/05/soap-envelope">
<tns:cancelReservationResp xmlns:tns="http://xxxx.com">
<tns:success>true</tns:success>
<tns:message/>
<tns:reservations>
<tns:garageID>47</tns:garageID>
<tns:barCode>barCode168</tns:barCode>
<tns:licensePlate>licensePlate168</tns:licensePlate>
<tns:orderNumber/>
<tns:used>false</tns:used>
<tns:cancelled>true</tns:cancelled>
<tns:startTime>2015-11-20 22:53:45.547</tns:startTime>
<tns:endTime>2015-11-21 22:53:45.547</tns:endTime>
<tns:cancelledTime>2015-11-19 00:51:58.717</tns:cancelledTime>
<tns:checkInTime/>
<tns:checkOutTime/>
<tns:grossPrice>152.6000</tns:grossPrice>
<tns:commFee>162.6000</tns:commFee>
<tns:customerName>customerName168</tns:customerName>
<tns:customerEmail>customerEmail168</tns:customerEmail>
<tns:customerPhone>customerPhone168</tns:customerPhone>
<tns:vehicleMake>vehicleMake168</tns:vehicleMake>
<tns:vehicleModel>vehicleModel68</tns:vehicleModel>
<tns:vehicleColor>vehicleColor168</tns:vehicleColor>
<tns:reentryAllowed>true</tns:reentryAllowed>
</tns:reservations>
</tns:cancelReservationResp>
</soapenv:Body>
</soapenv:Envelope>
I am getting this <tns:success>true</tns:success> value from $success variable but not getting anything from $garageID variable.
Any idea why $garageID is getting blank?
Thanks.

PHP Receiving XML

I have a small PHP script that is listening for a POST request. I'm expecting xml, always.
Normally I'm the guy sending the xml requests. But today I'm on the receiving side.
I figured it would be a simple case of listening for a $_POST, but I guess I may be incorrect - I'm getting nothing.
Here's my script that waits for anything xml:
<?php
if(isset($_POST)) {
mail("me#myemail.com","some title i want", print_r($_POST, true));
}else{
die("uh, what happened?");
}
?>
And here is a simple xml string I'm sending from another place:
<?php
$xml_data ='
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don\'t forget me this weekend!</body>
</note>
';
function sendXML2Server($URL,$XML){
$xml_data = trim($XML);
$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
echo sendXML2Server('https://someurl.com/inboundxml.php',$xml_data)
?>
And here's what I get in my email:
Array
(
)
I'm guessing I'm not working with an array correctly, but maybe there's something else I'm missing in all this. I'm expecting to get back the actual xml string.
You sending nothing but data, thats why PHP cannot interpreter this data as some key&value. So, you need to send it as a value of variable:
curl_setopt($ch, CURLOPT_POSTFIELDS, array('xml_data' => $xml_data));
or receive as a raw post data:
<?php
if(isset($HTTP_RAW_POST_DATA)) {
mail("me#myemail.com","some title i want", print_r($HTTP_RAW_POST_DATA, true));
}else{
die("uh, what happened?");
}
?>
CURLOPT_POSTFIELDS requires an array:
curl_setopt($ch, CURLOPT_POSTFIELDS, array('content'=>$xml_data));
Then retrieve it like:
<?php
if($_SERVER['REQUEST_METHOD']=='POST' && isset($_POST['content'])) {
mail("me#myemail.com","some title i want", print_r($_POST['content'], true));
}else{
die("uh, what happened?");
}
?>

django or php curl posting xml data

I want to do this payment getway request by sending this xml .
<?xml version="1.0" encoding="UTF-8"?>
<COBROAIRLINES>
<paymentService>
<id_company>0000</id_company>
<id_branch>5</id_branch>
<country>MEX</country>
<user>USUARIO</user>
<password>DE3C9FEF064F1459C30C0E7B</password>
<merchant>00000</merchant>
<reference>123pba</reference>
<tp_operation>12</tp_operation>
<creditCardType>V/MC</creditCardType>
<creditCardName>NOMBRE TH</creditCardName>
<creditCardNumber>AF3992EE603B743FC70D0D71F858C63C</creditCardNumber>
<creditCardExpMonth>AB3D</creditCardExpMonth>
<creditCardExpYear>AA3E</creditCardExpYear>
<creditCardCVV>291</creditCardCVV>
<initialDeferment>00</initialDeferment>
<numberOfPayments>06</numberOfPayments>
<planType>03</planType>
</paymentService>
<transaction>
<transactionTS>2008/01/01 10:00:00</transactionTS>
<currency>MXN</currency>
<orderAmount>1000</orderAmount>
<orderTotalTickets>1</orderTotalTickets>
<orderPromo>0</orderPromo>
<orderSource>000</orderSource>
<sdos>1</sdos>
</transaction>
<passengerFlight>
<passengerName>Juan Perez</passengerName>
<passengerTicketAmount>1000</passengerTicketAmount>
<passengerFrequentFlierNumber>96321</passengerFrequentFlierNumber>
<flightFare>A</flightFare>
<flightRoundTrip>0</flightRoundTrip>
<flightOriginCity>MEX</flightOriginCity>
<flightOriginCountry>MEX</flightOriginCountry>
<flightDestinationCity>TKY</flightDestinationCity>
<flightDestinationCountry>JAP</flightDestinationCountry>
<flightDaysTillDeparture>1</flightDaysTillDeparture>
<flightLayovers>0</flightLayovers>
</passengerFlight>
<userSalutation>Ing.</userSalutation>
<userName>Juan Perez</userName>
<userStreet>Heriberto Frias 1527</userStreet>
<userNeighborhood>Del Valle</userNeighborhood>
Confidential 13 de 25 Airlines Payment Iv6.0
<userCity>Mexico</userCity>
<userState>DF</userState>
<userZipCode>03100</userZipCode>
<userCountry>Mexico</userCountry>
<userPhone>5554425700</userPhone>
<userPhone2>5512345678</userPhone2>
<userEMail>correo#correo.com.mx</userEMail>
<userLogin>prueba</userLogin>
<userReturnCustomer>0</userReturnCustomer>
<billingName>Juan Perez</billingName>
<billingStreet>Corregidora</billingStreet>
<billingHouseNumber>92</billingHouseNumber>
<billingHouseNumberInt>1</billingHouseNumberInt>
<billingNeighborhood>Miguel Hidalgo</billingNeighborhood>
<billingMunicipality>Tlalpan</billingMunicipality>
<billingCity>Mexico</billingCity>
<billingState>DF</billingState>
<billingZipCode>14260</billingZipCode>
<billingCountry>Mexico</billingCountry>
<billingPhone>5515009000</billingPhone>
<billingPhone2>5515009020</billingPhone2>
<billingEMail>correo#correo.com</billingEMail>
<browserSessionID>org.apache.catalina.session.Sta...</browserSessionID>
<browserHostName>172.0.0.1</browserHostName>
<browserAccept>image/gif</browserAccept>
<browserAcceptEncoding>gzip, deflate</browserAcceptEncoding>
<browserAcceptCharset>ISO-8859-1,utf-8;q=0.7,*;q=0.7 </browserAcceptCharset>
<browserID>Mozilla/4.0 (compatible; MSIE 5.5)</browserID>
<browserIDLanguageCode>en-us,en;q=0.5</browserIDLanguageCode>
<browserCookie>CL=null</browserCookie>
<browserIP>172.452.16.23</browserIP>
<browserReferer>http://www.cualquiera.com</browserReferer>
<browserConnection>keep-alive</browserConnection>
<javascriptData> TF1;014;5;7;18068;6%2C0%2C6001%2C18000;....</javascriptData>
<customField1>ABCDEF</customField1>
<customField2></customField2>
<customField3></customField3>
<customField4></customField4>
<customField5></customField5>
</COBROAIRLINES>
the url of payment getway is https://dev.mitec.com.mx/wscobroSdos/CobroAirlines/?xml=
in documentation of payment getway , they have given xml=xml file content .
so basically i dont know it is GET or POST , but with no of charachter in xml i am assuming it will be POST.
so what i have tried ,
$xmldatafile="payment.xml";
$xmlData = file_get_contents($xmldatafile);
$URL = "https://dev.mitec.com.mx/wscobroSdos/CobroAirlines?xml=";
$ch = curl_init();
// curl_setopt($ch, CURLOPT_MUTE, 1);
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
echo $output = curl_exec($ch);
if(curl_errno($ch)) {
print curl_error($ch);
}
curl_close($ch);
and it is giving me this response don't know why what can i do ?
i think this is the paymentgetway site http://www.centrodepagos.com.mx/cdpweb/descargas.htm
the response m getting is :
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<CENTEROFPAYMENTS>
<reference></reference>
<response>error</response>
<foliocpagos></foliocpagos>
<auth></auth>
<cd_response></cd_response>
<cd_error>01</cd_error>
<nb_error>El xml enviado no corresponde a ningun modelo</nb_error>
<time>05:02:44</time>
<date>28/02/2012</date>
<voucher></voucher>
</CENTEROFPAYMENTS>
The same api also tried in django python , which is my ultimate goal.
import pycurl
ncServerURL='https://dev.mitec.com.mx/wscobroSdos/CobroAirlines?xml='
binaryptr = open('payment.xml','rb').read()
c = pycurl.Curl()
c.setopt(pycurl.URL, ncServerURL)
c.setopt(pycurl.POST, 1)
c.setopt(pycurl.HTTPHEADER, ["Content-type: text/xml"])
# c.setopt(c.URL, ncServerURL + '?xml=' + binaryptr)
# c.setopt(pycurl.TIMEOUT, ncServerMaxTime)
# c.setopt(pycurl.CONNECTTIMEOUT, ncServerMaxTime)
c.setopt(pycurl.NOSIGNAL, 1) # disable signals, curl will be using other means besides signals to timeout.
c.setopt(pycurl.POSTFIELDS, binaryptr)
import StringIO
b = StringIO.StringIO()
c.setopt(pycurl.WRITEFUNCTION, b.write)
c.perform()
ncServerData = b.getvalue()
print ncServerData
the response m getting is :
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<CENTEROFPAYMENTS>
<reference></reference>
<response>error</response>
<foliocpagos></foliocpagos>
<auth></auth>
<cd_response></cd_response>
<cd_error>01</cd_error>
<nb_error>El xml enviado no corresponde a ningun modelo</nb_error>
<time>05:02:44</time>
<date>28/02/2012</date>
<voucher></voucher>
</CENTEROFPAYMENTS>
tried with urllib2
import urllib2
import urllib
binaryptr = open('payment.xml','rb').read()
data = binaryptr
headers = {
'Content-Type': 'application/soap+xml; charset=utf-8'
}
req = urllib2.Request('https://dev.mitec.com.mx/wscobroSdos/CobroAirlines?xml=', data, headers)
response = urllib2.urlopen(req)
the_page = response.read()
print the_page
Got the same error as above.
It looks like it wants the xml in the url, rather than the body. This is pretty bad design, but try appending it to ?xml=
$URL = "https://dev.mitec.com.mx/wscobroSdos/CobroAirlines/?xml=" . $xmlData;

spell check using google.com/tbproxy/spell

I am using google spell check in my project and doing everything as suggested in the blogs but it doesn't seem to work for me. Can you please look at this and tell me what I am doing incorrect.
In my JavaScript:
function makeRequest(parameters, svalue) {
console.log("dv-- inside makerequest 1");
console.log("svalue =", svalue);
http_request.onreadystatechange = GetResponse;
http_request.open('POST', 'http://mysite.com/Project/spellify.php?lang=en', true);
data = '<?xml version="1.0" encoding="utf-8" ?>';
data +='<spellrequest textalreadyclipped="0" ignoredups="0" ignoredigits="0" ignoreallcaps="0"><text>';
data += svalue;
data += '</text></spellrequest>';
console.log("data =", data)
http_request.send(data);
}
function GetResponse(){
console.log("dv-- inside GetResponse-1 http_request.readyState =", http_request.readyState)
if (http_request.readyState == 4) {
console.log("dv-- inside GetResponse-2 http_request.status =", http_request.status)
if (http_request.status == 200) {
http_response = http_request.responseText;
console.log("dv --http_response =", http_response)
}
else {
console.log('There was a problem with the request' + '& http_request.status =' + http_request.status );
}
}
}
My PHP Code: spellify.php
$url="http://www.google.com/tbproxy/spell?lang=en&hl=en";
//$data = file_get_contents('php://input');
$data = '<?xml version="1.0" encoding="utf-8" ?><spellrequest textalreadyclipped="0" ignoredups="0" ignoredigits="0" ignoreallcaps="0"><text>hellow </text></spellrequest>';
$data = urldecode($data);
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$contents = curl_exec ($ch);
curl_close ($ch);
print $contents;
?>
I tried hardcoding the data in my php to make sure data was passed correctly and that is not an issue.
Firefox give an error:
Error: unclosed token
Source File: http://mysite.com/Project/spellify.php?lang=en
Line: 5, Column: 183
Source Code:
$data ='<?xml version="1.0" encoding="utf-8" ?><spellrequest textalreadyclipped="0" ignoredups="0" ignoredigits="0" ignoreallcaps="0"><text>hello thsi is graet</text><`/spellrequest>';
Chrome doesn't give any error, but show below in console:
dv-- inside makerequest 1
spellify.js:419svalue = hello worlda
spellify.js:432dv-- inside GetResponse-1 http_request.readyState = 1
spellify.js:427data = <?xml version="1.0" encoding="utf-8" ?><spellrequest textalreadyclipped="0" ignoredups="0" ignoredigits="0" ignoreallcaps="0"><text>hello worlda </text></spellrequest>
spellify.js:432dv-- inside GetResponse-1 http_request.readyState = 2
spellify.js:432dv-- inside GetResponse-1 http_request.readyState = 3
spellify.js:432dv-- inside GetResponse-1 http_request.readyState = 4
spellify.js:435dv-- inside GetResponse-2 http_request.status = 200
spellify.js:438dv --http_response = <?php
$url="http://www.google.com/tbproxy/spell?lang=en&hl=en";
// $data = file_get_contents('php://input');
$data = '<?xml version="1.0" encoding="utf-8" ?><spellrequest textalreadyclipped="0" ignoredups="0" ignoredigits="0" ignoreallcaps="0"><text>hello thsi is graet</text></spellrequest>';
$data = urldecode($data);
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$contents = curl_exec ($ch);
curl_close ($ch);
print $contents;
?>
Please suggest what could be corrected to make this work.
Thanks
You are using code from spellify.com, some sort of credit to original developer is appreciated.
1) You have incorrectly modified spellify.php file.
2-a) Spellify basically prepare http-request and parse http-response via Javascript src/spellify.js, so its incorrect to make any changes in spellify.php, rather you should check if you are referencing spellify/src/scriptaculous.js and spellify/src/prototype.js correctly.
2-b) Under same spellify.js you have hardcoded following line incorrectly;
http_request.open('POST', 'http://mysite.com/Project/spellify.php?lang=en', true);
It should be as follows;
http_request.open('POST', 'http://mysite.com/Project/spellify.php?lang=en'+parameters, true);
3) The time when spellify.php was written, there might have no issue with SSL verification, but now it wont return anything unless you ignore the SSL Verification, add following lines in spellify.php, before $contents = curl_exec ($ch);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
Here is sample implementation.
http://amitgandhi.in/2013/01/25/spell-check-utility-using-jquery-and-google-api/
You can add words dictionary. Variable $.SpellChecker.dicWords is a
javascript array which maintain this. You can use your database table
populate this array with existing words. Currently this app is not
connected to database so if you add your words then lifetime of words
would only till page reloads.
Uses google.com/tbproxy/spell api call (Written in PHP)

Categories