2016-12-08 13 views
0

経由でcURLのリクエストを送信しこの情報の送信について、私は行くにはどうすればよいPHP

$url = "http://ms.4url.eu/lookup"; 

はカールを使用して、私が現在使用していた:

$curl = curl_init($url); 
curl_setopt($curl, CURLOPT_HEADER, false); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($curl, CURLOPT_HTTPHEADER, 
     array("Content-type: application/json")); 
curl_setopt($curl, CURLOPT_POST, true); 
curl_setopt($curl, CURLOPT_POSTFIELDS, $json_data); 

$json_response = curl_exec($curl); 

$status = curl_getinfo($curl, CURLINFO_HTTP_CODE); 

if ($status != 201) { 
    die("Error: call to URL $url failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl)); 
} 


curl_close($curl); 

そのうちの結果(NGrok):

GET /testDir/curlPost.php HTTP/1.1

Accept: text/html, application/xhtml+xml, image/jxr, /

Accept-Language: en-GB

User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393

Accept-Encoding: gzip, deflate

Host: f0946724.ngrok.io

X-Forwarded-For: 92.11.143.199

200 OK HTTP/1.1 200 OK

Date: Thu, 08 Dec 2016 00:48:20 GMT

Server: Apache/2.4.23 (Win32) OpenSSL/1.0.2h PHP/7.0.9

X-Powered-By: PHP/7.0.9

Content-Length: 161

Content-Type: text/html; charset=UTF-8

Error: call to URL http://ms.4url.eu/lookup failed with status 0, response , curl_error Failed to connect to ms.4url.eu port 80: Connection refused, curl_errno 7

としてだけでなく、カールから述べエラー:

Error: call to URL http://ms.4url.eu/lookup failed with status 0, response , curl_error Failed to connect to ms.4url.eu port 80: Connection refused, curl_errno 7

感謝すべてのヘルプ、感謝します。

+0

まず、http:// ms4url.eu/lookupが到達可能ですか? HTTPステータスコード0を見たことがないためです。 –

+0

はいJson形式で指定されたデータのhttp要求はPOST/testDir/getPost.php HTTP/1.1ホストを返します:1f89e4a8.ngrok.io accept:application/json content-type:アプリケーション/ json content-length:198接続:閉じるX-Forwarded-For:5.44.233.221 {"id": "ea26d0b2-b839-46b9-9138-50cc791bab47"、 "msisdn": "44712​​3121234"、 "status": " 「GB」、「ネットワーク」:「O2」、「networkType」:「GSM」、「ported」:「No」、「NetworkCode」:「23471」、「countryName」:「UK」、「countryCode」: }。 –

+1

あなたの[カールエラーは7でないため、接続できません](https://curl.haxx.se/libcurl/c/libcurl- errors.html)、そして誰かがこれまでに[このような場合](http://stackoverflow.com/questions/9922562/how-to-resolve-curl-error-7-couldnt-connect-to-host)をstackoverflowで尋ねました。 googleのような別のドメインにcurlを呼び出そうとすることもできますか?失敗した場合はファイアウォールを確認してください。 –

答えて

0

私は、サーバーがHttp(80)ではなくHttps(443)接続を期待していることがわかりました。これは、リクエストを送信するときににURLを変更することで簡単に解決できました。 cURLで

関連する問題