I tried try to get Token, but answer always blank. What i doing wrong?
$post_string = '
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/">
<soap:Header/>
<soap:Body>
<tem:GetToken>
<tem:WebChanelID>8</tem:WebChanelID>
<tem:AccessCode>444555</tem:AccessCode>
</tem:GetToken>
</soap:Body>
</soap:Envelope>
';
$soap_do = curl_init();
curl_setopt($soap_do, CURLOPT_URL, "https://hma.ecvi.ru/service/webform.wsdl.php" );
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_TIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($soap_do, CURLOPT_POST, true );
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $post_string);
curl_setopt($soap_do, CURLOPT_HTTPHEADER, array('Content-Type: text/xml; charset=utf-8', 'Content-Length: '.strlen($post_string) ));
$result = curl_exec($soap_do);
$err = curl_error($soap_do);
I need to get an answer, but it's always blank.
Related
I searched this website for a helpful response for integrating a SOAP Request in PHP, but I didn't find anything that solved my problem.
I'm new to SOAP and can't figure out why I am not getting any response:
<?php
$xml = '<?xml version="1.0" encoding="utf-8"?>'.
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'.
' xmlns:xsd="http://www.w3.org/2001/XMLSchema"'.
' xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'.
'<soap:Body>'.
'<food xmlns="http://www.localhost:81/dbWIP/xml1.xml">'.
'<price>$5.95</price>'.
'</food>'.
'</soap:Body>'.
'</soap:Envelope>';
$url = "http://www.localhost:81/dbWIP/xml1.xml";
$ch = curl_init();
echo $ch;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$headers = array();
array_push($headers, "Content-Type: text/xml; charset=utf-8");
array_push($headers, "Accept: text/xml");
array_push($headers, "Cache-Control: no-cache");
array_push($headers, "Pragma: no-cache");
array_push($headers, "SOAPAction:http://www.localhost:81/dbWIP/xml1.xml");
if($xml != null) {
echo $xml;
curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml");
array_push($headers, "Content-Length: " . strlen($xml));
}
curl_setopt($ch, CURLOPT_USERPWD, "user_name:password"); /* If required */
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
echo $response;
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
echo"<br/> CODE:"$code;
curl_close($ch);
?>
I think you are missing URL from curl_init which will initialize a cURL session, but yours has no URL.
$curl = curl_init("http://www.localhost:81/dbWIP/xml1.xml");
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt ($curl, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);
//curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 1);
//curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $xml);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
And try setting your headers to
$headers = array(
'Content-type: text/xml;charset="utf-8"',
'Accept: text/xml',
'Cache-Control: no-cache',
'Pragma: no-cache',
'Content-length: ' . strlen($xml),
);
Try to remove the quotation marks:
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
I am trying to integrate the SOAP xml request using PHP CURL method I have tried a lot of methods to get a response from the client system but always goes for a failed message. Below is the code which I am trying it,
<?php
$envelope = '<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:rbss="RBSS"><soap:Header/><soap:Body><rbss:PushData><!--Optional:--><rbss:xml><RBSS><ead_Response_DateTime>20-05-2016 10:25:16 </Lead_Response_DateTime><Lead_Push_DateTime>20-05-2016 10:25:16 </Lead_Push_DateTime><Lead_Recd_DataTime>20-05-2016 10:25:16 </Lead_Recd_DataTime><FirstName>Ismail</FirstName><Phone1>7760120077</Phone1><Phone2>7760120077</Phone2><Email>test#gmail.com</Email><DOB>20-05-2016</DOB><Age>25</Age><Child_DOB>20-05-2002</Child_DOB><Child_Age></Child_Age><Pincode>400052</Pincode><City_Name>Bangalore</City_Name><Address>2, Akshardhamů..</Address><Annual_Income>1000000</Annual_Income><Annual_Income_Slab></Annual_Income_Slab><SMS_Keyword></SMS_Keyword><Short_Code></Short_Code><Circle_Operator></Circle_Operator><Sum_Assured></Sum_Assured><Premium_Pitched></Premium_Pitched><Company_Name>WRS </Company_Name><Website_Name>indiainverstors.in </Website_Name><UTN_Source>FaceBook </UTN_Source><Lead_Source></Lead_Source><Type_Of_Lead></Type_Of_Lead><Verification_Type></Verification_Type><Product_Name></Product_Name><Product_Category></Product_Category><No_of_Companies></No_of_Companies><Names_of_Companied></Names_of_Companied><SMS_Message_Sent></SMS_Message_Sent><Customer__Remarks></Customer__Remarks><FLAG></FLAG><Lead_Type>INCOMING_WEB</Lead_Type><Channel_Type>INTERNET</Channel_Type><Mode_Type>PREFIXED_APPOINTMENT</Mode_Type><Source_Type>Valueleaf</Source_Type><Campaign_Type>APR_16</Campaign_Type><Opportunity_Id>123456</Opportunity_Id><PROSPECT_ID></PROSPECT_ID><Title>MR</Title><UID></UID><LastName>Malik</LastName><Gender>Male</Gender><MaritalStatus></MaritalStatus><MobileNo>7760120077</MobileNo><AgeAtRetirement></AgeAtRetirement><VendorCSE_Name></VendorCSE_Name><TermOfPlan></TermOfPlan><Smoker_NonSmoker></Smoker_NonSmoker><VendorCode></VendorCode><MeetingDate>20-01-2017</MeetingDate><MeetingTime></MeetingTime><City_ID>11</City_ID><ID>123</ID><CallcenterID></CallcenterID><ADDLInfo1></ADDLInfo1><ADDLInfo2></ADDLInfo2></RBSS></rbss:xml></rbss:PushData></soap:Body></soap:Envelope>';
$soap_do = curl_init();
curl_setopt($soap_do, CURLOPT_URL, "http://company.service.com/IPRU_PFA_Vendor_Data/Service.asmx?op=PushData");
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_TIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($soap_do, CURLOPT_POST, true );
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $envelope);
curl_setopt($soap_do, CURLOPT_HTTPHEADER, array("Content-Type: text/xml", "Content-length: ".strlen($envelope)));
$result = curl_exec($soap_do);
print_r($result);
curl_close($soap_do);
if($result==true)
{
echo "success";
}
else
{
echo "Something went wrong";
}
?>
Everytime the else statement is giving the output. Can anyone say me where exactly I am going wrong.
I have xml data as
<ns:PartyIDs>
<ns:ID schemeName="PartyTypeNumber">009</ns:ID>
<ns:ID schemeName="PartyNumber">00038</ns:ID>
<ns:ID schemeName="PartySubNumber">00038</ns:ID>
</ns:PartyIDs>
i need to read this and print the attributes and value. Using PHP.
right now i am trying usin DOMDocument
$soap_do = curl_init();
curl_setopt($soap_do, CURLOPT_URL, $url );
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_TIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($soap_do, CURLOPT_POST, true );
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $domObject->saveXML());
curl_setopt($soap_do, CURLOPT_HTTPHEADER, array('Content-Type: text/xml; charset=utf-8', 'Content-Length: '.strlen($domObject->saveXML()) ));
$response = curl_exec($soap_do);
$xml = new SimpleXMLElement($response); //file from response
$fileName="Response".date("Ymd_H_i_s");
$xml->saveXML($fileName);
$doc = new DOMDocument();
$doc->load($fileName);//loading response file
Use $doc->getElementsByTagNameNS() instead.
See the manual for details: http://php.net/DOMDocument.getElementsByTagNameNS
You'll need to provide the $namespaceUri parameter which should have been specified in the root element of the XML file as xmlns:ns="http://...".
I have a problem with my cURL response, when I try to invoke the method of WSDL, I receive this weird text from my browser,
�d�ْ�<�_��[�7�4eS�#���8 �]��Q��A���>�t�,����]�1��%Y���4!l�^ZG��,8��v��������#ZJ�W��
r)0Ek����Q�����"Ᏹ�!�0��0����(�T�$���� Z��փ��UU���g������&�C�f
8�!��5��L�t{����6�?{jY�Q��?���K����3�D2�e �߱Oc����#^P��$�IΠ�4A[;�p�\7�����i5��+�\歖~=����)�����a�L�GJey�F����Ɍ��v]��<��z������N����\z��.�i:�S5��FgkM�hS���|,\�0�E9i=�+ӄ�!^WҶ�7�����0�w���+b�۹��[�;���fE4_ڑ�������u�Q)E��;�;�JL���������Ԩ�1��7[�$D���\�W���ۂU$9���
How can I solve this?
Here's my header
$headers = array(
"Accept-Encoding: gzip, deflate",
"Content-Type: text/xml;charset=\"UTF-8\"",
"SOAPAction: \"http://tempuri.org/"",
"Host: domain.com",
"Content-length: ".strlen($xml_post_string),
"Connection: Keep-Alive"
);
and here's my curl options
curl_setopt($soap_do, CURLOPT_URL, $url);
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 120);
curl_setopt($soap_do, CURLOPT_TIMEOUT, 120);
curl_setopt($soap_do, CURLOPT_AUTOREFERER, true); // new
curl_setopt($soap_do, CURLOPT_MAXREDIRS, 10); // new
curl_setopt($soap_do, CURLOPT_FOLLOWLOCATION, true); // new
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($soap_do, CURLOPT_POST, true );
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $xml_post_string);
curl_setopt($soap_do, CURLOPT_VERBOSE, TRUE);
curl_setopt($soap_do, CURLOPT_HTTPHEADER, $headers);
Thank you guys for your comment, I have solve the issue now, shout out to Grokify, I just remove the Accept-Encoding: gzip, deflate and it is now readable.
I had a similar problem. Adding working headers (As of my browser) solved it for me.
Current working code of mine:
$headers = array("User-Agent: ********User Agent********");
$ch = curl_init("******URL*******");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$data= curl_exec($ch);
curl_close($ch);
I am not sure if this is the right place for it, but I am hoping a few of you are familiar with PHP cURL as well as SOAPUI.
I have managed to successfully submit a web services request using SOAPUI, but have had no luck using php. PHP is currently timing out at 30 seconds (I also tried raising the timeout to 3mins). The SOAPUI request takes about 3 seconds to finish.
If any of you could spot where I went wrong, it would be greatly appreciated!
Thanks
Below are my properties for SOAPUI - endpoint is https://ccws-services.ecollege.com/EnterpriseServices/v2.1/EnterpriseCourse.svc:
SOAPUI Request:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:urn="urn:eclg:coursecopy:enterprisecourse" xmlns:v2="http://CCWS-Services.eCollege.com/EnterpriseServices/Types/v2.1/">
<soap:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsa:Action>urn:eclg:coursecopy:enterprisecourse:createcoursesection:request</wsa:Action>
<wsa:To>http://ccws-services.ecollege.com/EnterpriseServices/v2.1/EnterpriseCourse.svc</wsa:To>
</soap:Header>
<soap:Body>
<urn:CreateCourseSection>
<urn:createCourseSection>
***REMOVED****
</urn:createCourseSection>
</urn:CreateCourseSection>
</soap:Body>
</soap:Envelope>
I took the RawRequest from SOAPUI and used it as the XML payload for PHP ($post_string).
Here is my PHP code -I suspect the error comes from the SOAPAction, which I retrieved from SOAPUI's Operation Properties:
define('XML_POST_URL', 'https://ccws-services.ecollege.com/EnterpriseServices/v2.1/EnterpriseCourse.svc');
$headers = array(
'Content-Type: text/xml; charset=utf-8',
'Content-Length: '.strlen($post_string),
'Accept: text/xml',
'Cache-Control: no-cache',
'Pragma: no-cache',
'SOAPAction: urn:eclg:coursecopy:enterprisecourse:createcoursesection:request'
);
/**
* Initialize handle and set options
*/
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, XML_POST_URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 4000);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
/**
* Execute the request and also time the transaction
*/
$result = curl_exec($ch);
You can try this. This is what I used when I wound up using cURL in .php for a SOAP Web-Service.
$envelope = '<soap:Envelope> .... </soap:Envelope>';
$soap_do = curl_init();
curl_setopt($soap_do, CURLOPT_URL, "https://ccws-services.ecollege.com/EnterpriseServices/v2.1/EnterpriseCourse.svc" );
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_TIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($soap_do, CURLOPT_POST, true );
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $envelope);
curl_setopt($soap_do, CURLOPT_VERBOSE, TRUE);
curl_setopt($soap_do, CURLOPT_HTTPHEADER, array("Content-Type: text/xml","SOAPAction: \"/soap/action/query\"", "Content-length: ".strlen($envelope)));
$result = curl_exec($soap_do);
I do time out trying to connect to it. Try it on your end and see if it works with your username and password.