1

CURLを使用してphpサイトを開発していますが、ローカルサーバーでのみ機能し、ライブサーバーでは機能しません。「ホストに接続できませんでした」というエラーが返されます。

CURL iSがライブサーバーにインストールされており、テスト済みです。

SSLがライブサーバーにインストールされており、curlを使用してポート9301に接続しています

すなわち;http://xx.xxx.xx.xxx:9301/test。

これが私のコードです:

    $request =  'http://xx.xxx.xx.xxx:9301/test'; 
    // The request parameters 
    $context = 'something'; 

    // urlencode and concatenate the POST arguments 
    $postargs = 'xmlRequest='.urlencode($context);
    $session = curl_init($request); 
   // Tell curl to use HTTP POST
    curl_setopt ($session, CURLOPT_POST, true); 
    // Tell curl that this is the body of the POST
    curl_setopt($ch, CURLOPT_PORT, '9301');


    curl_setopt ($session, CURLOPT_POSTFIELDS, $postargs); 
    // Tell curl not to return headers, but do return the response
    curl_setopt($session, CURLOPT_HEADER, false); 
    curl_setopt($session, CURLOPT_RETURNTRANSFER, true);

    $response = curl_exec($session); 
   //echo curl_getinfo($session);   
    echo $err = 'Curl error: ' . curl_error($session);
   curl_close($session); 
   echo $response;

私のテストから、Curl経由でポートアドレスに接続できないことは明らかです。ポートアドレスに接続するには、サーバー設定を変更する必要がありますか?

4

1 に答える 1

7
curl_setopt($ch, CURLOPT_PORT, '9301');

それがあなたの問題です。ハンドルは$chあなたの場合ではありませんが、$session

ただのタイプミスだと思います。

一般的に:開発中にすべてのエラーを表示するようにしてください。それらをログに記録するか、画面に表示します。あなたはこれを簡単に捕まえたでしょう。

于 2012-07-25T10:03:50.977 に答える