开发者

trouble understanding cURL

There's a URL I need to pass to retrieve sto开发者_如何学运维ck availability from my supplier's server. I receive the expected response in the browser when simply entering the following url into the address bar:

https://stage-elink2.unitedstationers.com/iLink2/InterlinkDirect.asp?RequestTransmission=OE01XXX            DL2003-02-0616:32:16000100363XXXXXX   001039XXXXXX9        AMFXXXXXX   ACC11038       N&RequestType=3

The 'X's represent my userid & password information. The spaces represent fields for future use.

I'm trying to get the above string to work using cURL, but I'm not exactly sure how to do this. This is what I have so far. I'm not getting any response whatsoever and I'm not sure how to error check or step through to see where the problem lies.

my php cURL code:

$url = "https://stage-elink2.unitedstationers.com/iLink2/InterlinkDirect.asp";

$post_data = "RequestTransmission=OE01XXXX            DL2003-02-  0616:32:16000100363XXXXXX   001039XXXXXX9        AMFXXXXXX   ACC11038       N&RequestType=3";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$result = curl_exec($ch);
curl_close($ch);
echo $result;

Any help is appreciated. Thank you.


Try to use GET:

$url = "https://stage-elink2.unitedstationers.com/iLink2/InterlinkDirect.asp?RequestTransmission=OE01XXX DL2003-02-0616:32:16000100363XXXXXX 001039XXXXXX9 AMFXXXXXX ACC11038 N&RequestType=3";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$result = curl_exec($ch);

curl_close($ch);

echo $result;


After further research, I found the solution below to work.

This article on devzone really helped explain how to use cURL.

This article help with an SSL error I was receiving (error #60 - cURL error:SSL certificate problem, verify that the CA cert is OK).

$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_USERPWD, "userid:password"); //replace with usedid:password
curl_setopt ($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_TIMEOUT, 3);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $post_string); 
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 1);  //solved SSL error message
curl_setopt ($ch, CURLOPT_CAINFO, "cacert.pem");  //solved SSL error message
$result = curl_exec($ch);  
curl_close($ch);
echo $result;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜