URL在接受异常后在浏览器中正常工作,但不能在curl中工作。
我的代码如下:::
PHP代码:
<?php
$str1 = "https://50.60.70.80/servlet/API";
$url = $str1."?".$_SERVER['QUERY_STRING'];
echo $url;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt( $ch , CURLOPT_SSL_VERIFYHOST, true);
$data = curl_exec($ch);
echo curl_errno($ch);
if (curl_errno($ch)) {
echo 'Error: ' . curl_error($ch);
}
else {
echo 'Success: '.$data;
}
curl_close($ch);
?>
URL : https://50.60.70.80/servlet/API?userName=Test&password=pwd&message=My_Message&mobile=5555558888
Error getting while using through command line with "-k" and "-v":
***** About to connect() to 50.60.70.80 port 443 (#0)
* Trying 50.60.70.80... connected
* Connected to 50.60.70.80 (50.60.70.80) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
* warning: ignoring value of ssl.verifyhost
* skipping SSL peer certificate verification
* SSL connection using TLS_DHM_RSA_W1TH_AES_128_CBC_SEA
* Server certificate:
* subject: E=abcd@mnmn.com,OU=lelna,O=teledna
* start date: Mar 01 09:51:25 2013 GMT
* expire date: Mar 01 09:51:25 2014 GMT
* common name: (nil)
* issuer: E=abcd@mnmn.com,OU=lelna,O=teledna
> GET /servlet/API?UserName=Test HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.3.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: 50.60.70.80
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: Apache-Coyote/1.1
< Pragma: no-cache
< Cache-Control: no-store
< Expires: Thu, 01 Jan 1970 00:00:00 GMT
< Transfer-Encoding: chunked
< Date: Thu, 08 Aug 2013 16:38:57 GMT
<
status=FAILED,transid=4526698561,reasoncode=201
* Connection #0 to host 50.60.70.80 left intact
* Closing connection #0****
我使用以下版本:: PHP版本 - 5.3.3 CURL版本 - 7.19.7 使用Apache
答案 0 :(得分:1)
您需要添加此
已编辑:
curl_setopt( $ch ,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');