Recently, I have made some changes on my URL from HTTP to HTTPS, everything is working with HTTP but when I changed it to HTTPS, I'm getting empty response on both side curl_exec($soap_do) and curl_error($soap_do). Any Ideas?
$url= "https://api.AppMain.svc?wsdl"; // asmx URL of WSDL
$soap_do = curl_init();
set_time_limit(0);
curl_setopt($soap_do, CURLOPT_URL, $url);
curl_setopt($soap_do, CURLOPT_AUTOREFERER, true);
curl_setopt($soap_do, CURLOPT_MAXREDIRS, 10);
curl_setopt($soap_do, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($soap_do, CURLOPT_CAINFO, APPPATH . "/RSA/GeoTrustGlobalCA.crt");
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);
// Converting
$response = curl_exec($soap_do);
$error = curl_error($soap_do);
if(curl_errno($soap_do))
{
echo "Curl Failed: " . curl_errno($soap_do), "<br/>";
echo curl_error($soap_do);
} else {
echo "Success"; // I'm getting success result but when I print $response it's blank.
}
Related
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 tried accessing a website using curl and it just output Object moved to here. I used curl_error but doesn't show any errors.
$url = "https:somewebsite.com";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // Accepts all CAs
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
//curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
if(curl_error($ch))
{
echo 'error:' . curl_error($ch);
}
curl_close($ch);
echo $output;
?>
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'm trying to make a get request in php using curl. This is what I'm doing:
$curl = curl_init();
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "username:password");
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);
printf($result);
But $result doesn't print out anything, no success or failure message. I've successfully reached the endpoint via postman and in a web browser so I know it works. Printing out $curl prints: "Resource #1" which makes me think curl is properly installed on the server.
I'm not sure what steps to take next to make things work.
Add a few more option for troubleshooting purposes.
Check for an error response.
If no error, get the details:
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT,10);
curl_setopt($ch, CURLOPT_FAILONERROR,true);
curl_setopt($ch, CURLOPT_ENCODING,"");
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_HEADER, true);
$data = curl_exec($ch);
if (curl_errno($ch)){
$data .= 'Retreive Base Page Error: ' . curl_error($ch);
}
else {
$skip = intval(curl_getinfo($ch, CURLINFO_HEADER_SIZE));
$head = substr($data,0,$skip);
$data = substr($data,$skip);
$info = curl_getinfo($ch);
$info = var_export($info,true);
}
echo $head;
echo $info;
You can utilize curl's CURLOPT_VERBOSE and CURLOPT_STDERR like this:
$curl = curl_init();
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "username:password");
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$verbose = fopen('php://temp', 'w+');
curl_setopt($curl, CURLOPT_VERBOSE, true);
curl_setopt($curl, CURLOPT_STDERR, $verbose);
$result = curl_exec($curl);
curl_close($curl);
rewind($verbose);
$verboseLog = stream_get_contents($verbose);
echo "Verbose information:\n<pre>", htmlspecialchars($verboseLog), "</pre>\n";
printf($result);
I am supposed to receive a variable called "D" after server receives the string I sent. How do I get it to receive the server responses message?
$soapme = curl_init();
curl_setopt($soapme, CURLOPT_URL, $url );
curl_setopt($soapme, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($soapme, CURLOPT_TIMEOUT, 10);
curl_setopt($soapme, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soapme, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soapme, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($soapme, CURLOPT_POST, true );
curl_setopt($soapme, CURLOPT_POSTFIELDS, $post_string);
curl_setopt($soapme, CURLOPT_HTTPHEADER, array('Content-Type: text/xml; charset=utf-8', 'Content-Length: '.strlen($post_string) ));
curl_setopt($soapme, CURLOPT_USERPWD, $user . ":" . $password);
curl_setopt($soapme, curlOPT_VERBOSE, 1);
curl_exec($soapme);
I notice I get a 1 as a result when I do not use ReturnTransfers. What does this 1 mean?
$result = curl_exec($soapme);
echo $result;