Marthaj
asked on
PHP Curl Problem
I have inherited a project and I have never worked with curl before. I am working in localhost mode, using PHP 5.6.25, Wampserver on a windows 10 computer. I have copied the libeay.dll and ssleay32.dll are copied to my wndows/system32 directory, the php.ini has the extension listed for curl_dll correctly and when I display the extensions loaded via the option in Wampserver, it is checked marked etc. There is no error msgs pertaining to either one in the PHP error log.
In addition, the phpinfo listing shows curl is installed with http, and a lot of other protocols.
I have checked my coding and I do not see where I have any double quotes, yet it tells me the following:
As I understand it, PHP thinks I am using a protocol ""http. but I sure don't see the error in my coding.
Another thing that I don't understand is when I issue the echo command to display the $xmlmsg, it only displays the values of the variables - $txtusername, $txtpassword ,$bookingid - which display the correct values - and nothing else - why is this? I can the whole $xmlmsg in IE Tools. But I find this strange.
I have listed my coding below, the website, mysitecom, is fictitious for posting. And what I see in Fiddler v4.
Any help appreciated...
And this is what I see using Fiddler v4:
In addition, the phpinfo listing shows curl is installed with http, and a lot of other protocols.
I have checked my coding and I do not see where I have any double quotes, yet it tells me the following:
Protocol ""http" not supported or disabled in libcurl
As I understand it, PHP thinks I am using a protocol ""http. but I sure don't see the error in my coding.
Another thing that I don't understand is when I issue the echo command to display the $xmlmsg, it only displays the values of the variables - $txtusername, $txtpassword ,$bookingid - which display the correct values - and nothing else - why is this? I can the whole $xmlmsg in IE Tools. But I find this strange.
I have listed my coding below, the website, mysitecom, is fictitious for posting. And what I see in Fiddler v4.
Any help appreciated...
$xmlmsg = '';
$xmlmsg = '<?xml version="1.0" encoding="utf-8"?> ';
$xmlmsg = $xmlmsg . '<soap:Envelope xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance';
$xmlmsg = $xmlmsg . ' xmlns:xsd=http://www.w3.org/2001/XMLSchema';
$xmlmsg = $xmlmsg . ' xmlns:soap=http://schemas.xmlsoap.org/soap/envelope/>';
$xmlmsg = $xmlmsg . '<soap:Header>';
$xmlmsg = $xmlmsg . '<GatewaySoapAuthentication xmlns=http://ws.mysite.com/>';
$xmlmsg = $xmlmsg . '<Username>'. $txtusername .'</Username>';
$xmlmsg = $xmlmsg . '<Password>'. $txtpassword .'</Password>';
$xmlmsg = $xmlmsg . '</GatewaySoapAuthentication>';
$xmlmsg = $xmlmsg . '</soap:Header>';
$xmlmsg = $xmlmsg . '<soap:Body>';
$xmlmsg = $xmlmsg . '<GetBookingDetails xmlns=http://ws.mysite.com/>';
$xmlmsg = $xmlmsg . '<BookingDetailsRequest>';
$xmlmsg = $xmlmsg . '<BookingNumber>'. $bookingid .'</BookingNumber>';
$xmlmsg = $xmlmsg . '</BookingDetailsRequest>';
$xmlmsg = $xmlmsg . '</GetBookingDetails>';
$xmlmsg = $xmlmsg . '</soap:Body>';
$xmlmsg = $xmlmsg . '</soap:Envelope>';
echo $xmlmsg;
// assemble header content
$header = array(
'Content-type: text/xml; charset=uf-8',
'Content-length: ' . strlen($xmlmsg),
'SOAPAction: http://ws.mysite.com/GetBookingDetails',
'Connection: close',
);
// setup curl parameters
$url = trim('http://ws.mysite.com/test/Gateway.asmx');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_TIMEOUT,300);
curl_setopt($ch,CURLOPT_POSTFIELDS, $xmlmsg);
$data = curl_exec($ch);
if(curl_errno($ch))
{
$errmsg = curl_error($ch);
// echo 'am here' . $errmsg . '<br>';
print curl_error($ch);
}else{
curl_close($ch);
}
And this is what I see using Fiddler v4:
<?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:Header><GatewaySoapAuthentication xmlns="http://ws.mysite.com/"><Username>mypasswrd</Username><Password>dogs</Password></GatewaySoapAuthentication></soap:Header><soap:Body><GetBookingDetails xmlns="http://ws.mysite.com/"><BookingDetailsRequest><BookingNumber>1</BookingNumber></BookingDetailsRequest></GetBookingDetails></soap:Body></soap:Envelope>Protocol ""http" not supported or disabled in libcurl
ASKER
Thank you for responding. I am a bit confused here - where would i plug in http://google.com in coding - in all spots where I used mysite.com?
When I look at FIddler v4 - it shows all my http strings encased in double quotes.
When I look at FIddler v4 - it shows all my http strings encased in double quotes.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Also, the quote marks in the message appear to be odd. See the characters marked by the "V"
/* VV V
<?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:Header><GatewaySoapAuthentication xmlns="http://ws.mysite.com/"><Username>mypasswrd</Username><Password>dogs</Password></GatewaySoapAuthentication></soap:Header><soap:Body><GetBookingDetails xmlns="http://ws.mysite.com/"><BookingDetailsRequest><BookingNumber>1</BookingNumber></BookingDetailsRequest></GetBookingDetails></soap:Body></soap:Envelope>Protocol ""http" not supported or disabled in libcurl
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thank you both for responding and wow - I have a lot to review. I know it would be very good to post the actual url but I am not allowed to post it publicly. I can send it privately. I need to digest all of this information - I learn so much using EE. Let me know if you wish to have me send the url privately - again, thank you all. Please give me a day as today is a very big holiday for my family...}
am not allowed to post it {the actual URL} publiclyUnderstood, Happy Easter. Best of luck with your project.
ASKER
Thank you both for responding and Happy Belated Easter too!
Ray, I executed your page as it - wow - I posted your results below using your url etc.. I like the structure of using heredocs - I have used them before but didn't think to use them in my page for this purpose - learned something new. And I executed your coding substituting the fictitious url with the good one - got good results too. So that is a step forward.
gr8gonzo - thank you for correcting my thinking on what I had thought about the - "'http - the fact that php can use single or double quotes sometimes can cause some real errors. I have not used curl before this project so its a bit of learning curve on how to handle urls etc. when they need to be encased with double quotes. Looking at Rays comment, I guess the bet way is to use heredocs. But what if you didn't use heredocs - then do I understand to use double qoutes - correct?
Anyway, I am going to try both suggestions and see what happens.
Again, I thank you both for responding as it is appreciated.
I will be posting more after testing.
Ray, I executed your page as it - wow - I posted your results below using your url etc.. I like the structure of using heredocs - I have used them before but didn't think to use them in my page for this purpose - learned something new. And I executed your coding substituting the fictitious url with the good one - got good results too. So that is a step forward.
gr8gonzo - thank you for correcting my thinking on what I had thought about the - "'http - the fact that php can use single or double quotes sometimes can cause some real errors. I have not used curl before this project so its a bit of learning curve on how to handle urls etc. when they need to be encased with double quotes. Looking at Rays comment, I guess the bet way is to use heredocs. But what if you didn't use heredocs - then do I understand to use double qoutes - correct?
Anyway, I am going to try both suggestions and see what happens.
Again, I thank you both for responding as it is appreciated.
I will be posting more after testing.
POST_Response_Object Object
(
[href] => https://Iconoun.com/demo/request_reflector.php
[title] => TESTING 1 2 3...
[http_code] => 0
[errno] => 60
[error] =>
[info] => Array
(
[url] => https://Iconoun.com/demo/request_reflector.php
[content_type] =>
[http_code] => 0
[header_size] => 0
[request_size] => 0
[filetime] => -1
[ssl_verify_result] => 1
[redirect_count] => 0
[total_time] => 0.219
[namelookup_time] => 0.032
[connect_time] => 0.094
[pretransfer_time] => 0
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => -1
[upload_content_length] => -1
[starttransfer_time] => 0
[redirect_time] => 0
[redirect_url] =>
[primary_ip] => 69.65.21.212
[certinfo] => Array
(
)
[primary_port] => 443
[local_ip] => 192.168.0.7
[local_port] => 54381
)
[document] =>
)
POST_Response_Object Object
(
[href] => https://Iconoun.com/demo/request_reflector.php
[title] => TESTING 1 2 3...
[http_code] => 0
[errno] => 60
[error] =>
[info] => Array
(
[url] => https://Iconoun.com/demo/request_reflector.php
[content_type] =>
[http_code] => 0
[header_size] => 0
[request_size] => 0
[filetime] => -1
[ssl_verify_result] => 1
[redirect_count] => 0
[total_time] => 0.219
[namelookup_time] => 0.032
[connect_time] => 0.094
[pretransfer_time] => 0
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => -1
[upload_content_length] => -1
[starttransfer_time] => 0
[redirect_time] => 0
[redirect_url] =>
[primary_ip] => 69.65.21.212
[certinfo] => Array
(
)
[primary_port] => 443
[local_ip] => 192.168.0.7
[local_port] => 54381
)
)
ASKER
Thank you both very much. I have learned new things for the future.
what if you didn't use heredocs - then do I understand to use double quotes - correct?Yes, that's basically correct. Here's the link to the docs that describe HEREDOC strings. Heed, but do not be put off by the warning on this page.
http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
xmlmsg = $xmlmsg . '<soap:Envelope xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance';
Put double quotes around ALL the attribute values:
$xmlmsg = $xmlmsg . '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ';
Open in new window