bradley525
asked on
cURL and PHP GET
Hello,
I am trying to use cURL to send a get request and recieve an XML response. The url I am using is ..
when i put it into the browser I get the following response, which is correct..
I am trying to use cURL and I keep getting a boo(false) returned.. Any help would be greatly appreciated.
Thanks
I am trying to use cURL to send a get request and recieve an XML response. The url I am using is ..
https://securegate.nmp.neuroticmedia.net/WebServices/CatalogService.asmx/artist_export_since_date?APIKey=xxxxxxxxxxxxxxxxxxxxxxxxxxx&Date=04/01/14
when i put it into the browser I get the following response, which is correct..
<SimpleResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="https://securegate.nmp.neuroticmedia.net/Common/XSDClasses/SimpleResponse.xsd">
<SimpleResponse_data>
<Message>
<ReturnValue>
https://az553772.vo.xxxxxx.net/xxxxxxxxxxxxxx/c2b0e458-e679-4ff8-b464-3e1decf4c1e8_artist.zip
</ReturnValue>
<ResponseCode>0</ResponseCode>
</Message>
</SimpleResponse_data>
</SimpleResponse>
I am trying to use cURL and I keep getting a boo(false) returned.. Any help would be greatly appreciated.
Thanks
Okay I will try a good example of this may be available at koders.com now http://code.ohloh.net
The following was modified code I wrote from 2005:
This was anonymous-ized for security and legal reasons but it should get you going
I recall it is essential your request xml in this case the string $headr contains
the xml request message contents and the result shows the response.
In this case a proxy was also in use but I imagine minus the proxy settings should work.
REMEMBER the key is to have an accurate request message to get a proper response and to have full authorization for the transaction as well.
<?
$URL = "https://remoteserverxyz.xyz.com";
$headr = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
$headr .="<FDXSubscriptionRequest xmlns:api=\"http://www.remotexyz.com/fsmapi\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"";
$headr .=" xsi:noNamespaceSchemaLocat ion=\"FDXS ubscriptio nRequest.x sd\">";
$headr .="<RequestHeader>";
$headr .="<CustomerTransactionIde ntifier>St ring</Cust omerTransa ctionIdent ifier>";
$headr .="<AccountNumber>33349680 0</Account Number>";
$headr .="</RequestHeader>";
$headr .="<Contact>";
$headr .="<PersonName>Perry Rhodan</PersonName>";
$headr .="<City>New York</City>";
$headr .="<StateOrProvinceCode>NY </StateOrP rovinceCod e>";
$headr .="<PostalCode>11138</Post alCode>";
$headr .="<CountryCode>US</Countr yCode>";
$headr .="</Address>";
$headr .="</FDXSubscriptionReques t>";
if (isset($_GET["site"])) { $URL = $_GET["site"]; }
$ch = curl_init();
echo "URL = $URL <br>\n";
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt ($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt ($ch, CURLOPT_PROXY,"remoteserve rxyz.com:3 128");
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_TIMEOUT, 520);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $headr);
$result = curl_exec ($ch); // Where the req uest was made
// the $result string contains the response xml
echo "<hr><br>\n";
echo 'Errors: ' . curl_errno($ch) . ' ' . curl_error($ch) . '<br><br>';
echo "<hr><br>\n";
curl_close ($ch);
print "result - $result";
echo "<hr><br>\n";
?>
The following was modified code I wrote from 2005:
This was anonymous-ized for security and legal reasons but it should get you going
I recall it is essential your request xml in this case the string $headr contains
the xml request message contents and the result shows the response.
In this case a proxy was also in use but I imagine minus the proxy settings should work.
REMEMBER the key is to have an accurate request message to get a proper response and to have full authorization for the transaction as well.
<?
$URL = "https://remoteserverxyz.xyz.com";
$headr = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
$headr .="<FDXSubscriptionRequest
$headr .=" xsi:noNamespaceSchemaLocat
$headr .="<RequestHeader>";
$headr .="<CustomerTransactionIde
$headr .="<AccountNumber>33349680
$headr .="</RequestHeader>";
$headr .="<Contact>";
$headr .="<PersonName>Perry Rhodan</PersonName>";
$headr .="<City>New York</City>";
$headr .="<StateOrProvinceCode>NY
$headr .="<PostalCode>11138</Post
$headr .="<CountryCode>US</Countr
$headr .="</Address>";
$headr .="</FDXSubscriptionReques
if (isset($_GET["site"])) { $URL = $_GET["site"]; }
$ch = curl_init();
echo "URL = $URL <br>\n";
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt ($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt ($ch, CURLOPT_PROXY,"remoteserve
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_TIMEOUT, 520);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $headr);
$result = curl_exec ($ch); // Where the req uest was made
// the $result string contains the response xml
echo "<hr><br>\n";
echo 'Errors: ' . curl_errno($ch) . ' ' . curl_error($ch) . '<br><br>';
echo "<hr><br>\n";
curl_close ($ch);
print "result - $result";
echo "<hr><br>\n";
?>
As for the SSL part I believe you can specify the host as https: and perhaps specify the SSL_VERIFYPEER as TRUE. Not sure about how to handle a private key there
Try doing a search for curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
and find that code. the repository of open source code may be of help in addition.
Try doing a search for curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
and find that code. the repository of open source code may be of help in addition.
Better yet do a site search in google search on only the site site:curl.haxx.se "CURLOPT_SSL_VERIFYPEER, TRUE" or "using SSL" maybe. This is the home of curl searching it should get you right to the sample or man page you need.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I recommend Ray's demo, especially if you are using PHP less than version 5.3.8. The version of 'libcurl' included in previous versions doesn't do CURLOPT_SSL_VERIFYHOST and CURLOPT_SSL_VERIFYPEER correctly on several sites I checked.
ASKER
HI Savant,
I tired to use your sample code above and it did begin to work, but it returned an error, any idea what this error is?
I tired to use your sample code above and it did begin to work, but it returned an error, any idea what this error is?
CURL FAIL: https://securegate.nmp.neuroticmedia.net/WebServices/CatalogService.asmx/artist_export_since_date?APIKey=xxxxxxxxxxxxxxxx&Date=04/01/14 TIMEOUT=5, CURL_ERRNO=28array(22) {
["url"]=>
string(155) "https://securegate.nmp.neuroticmedia.net/WebServices/CatalogService.asmx/artist_export_since_date?APIKey=xxxxxxxxxxxxxxxxxx&Date=04/01/14"
["content_type"]=>
NULL
["http_code"]=>
int(0)
["header_size"]=>
int(0)
["request_size"]=>
int(571)
["filetime"]=>
int(-1)
["ssl_verify_result"]=>
int(0)
["redirect_count"]=>
int(0)
["total_time"]=>
float(5.003475)
["namelookup_time"]=>
float(0.186635)
["connect_time"]=>
float(0.210813)
["pretransfer_time"]=>
float(0.281978)
["size_upload"]=>
float(0)
["size_download"]=>
float(0)
["speed_download"]=>
float(0)
["speed_upload"]=>
float(0)
["download_content_length"]=>
float(-1)
["upload_content_length"]=>
float(0)
["starttransfer_time"]=>
float(0)
["redirect_time"]=>
float(0)
["certinfo"]=>
array(0) {
}
["redirect_url"]=>
string(0) ""
}
<pre>
<strong>https://securegate.nmp.neuroticmedia.net/WebServices/CatalogService.asmx/artist_export_since_date?APIKey=xxxxxxxxxxxxxxxxx&Date=04/01/14</strong>
Please see http://curl.haxx.se/libcurl/c/libcurl-errors.html
Error code 28 means "timed out." You might want to increase the time or contact the publisher of the web service to see if the service is up at the moment.
Check the function definition and function call for the value of $timeout.
Error code 28 means "timed out." You might want to increase the time or contact the publisher of the web service to see if the service is up at the moment.
Check the function definition and function call for the value of $timeout.
ASKER
Worked perfect, just need to fix the timeout issue..Not an issue with the script.
Gr8! Thanks for using EE and thanks for the points, ~Ray
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
Anyway, use echo curl_error($ch) to know about errors. It's better if you use try..catch block to intercept errors and btw it's ususally better if you post the code here when you ask a question :-) You have posted the url and the expected repoonse, but not the code which fails and we can't not simply guess what's going wrong.