0

WireShark からのダンプは次のとおりです。

POST /drm/drm_production_v2.php HTTP/1.1

content-length: 278

content-type: text/xml

User-Agent: UserAgent 1.0

Connection: Keep-Alive

Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=

host: www.example.com



<methodCall>
  <methodName>aMethod</methodName>
  <params>
    <param>
      <value>
        <base64>dXNlcm5hbWU6cGFzc3dvcmQ=</base64>
      </value>
    </param>
    <param>
      <value>
        <struct/>
      </value>
    </param>
  </params>
</methodCall>

xml を別のファイルに保存しました。これが私がやっていることです:

<?php

function httpsPost($Url, $xml_data, $headers)
{
   // Initialisation
   $ch=curl_init();
   // Set parameters
   curl_setopt($ch, CURLOPT_FORBID_REUSE, 1); 
   curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
   curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
   curl_setopt($ch, CURLOPT_URL, $Url);
   // Return a variable instead of posting it directly
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch, CURLOPT_USERPWD,"username:password");

   // Activate the POST method
   curl_setopt($ch, CURLOPT_POST, 1) ;
   curl_setopt($ch,CURLOPT_USERAGENT,"UserAgent 1.0"); 
   // Request
   curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data);
   curl_setopt($ch, CURLOPT_TIMEOUT, 999);

   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
   curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

   // execute the connexion
   $result = curl_exec($ch);
   // Close it
   curl_close($ch);
   return $result;
}
$str='username:password';
$auth=base64_encode($str);
$request_file = "./request.xml"; 
$fh = fopen($request_file, 'r'); 
$filesize=filesize($request_file);
echo $filesize;
$xml_data = fread($fh,$filesize);

fclose($fh);    

$url = 'http://www.example.com';

$header = array();
$header[] = "POST /drm/drm_production_v2.php HTTP/1.1";
$header[] = "Content-type: text/xml";
$header[] = "content-length: ".$filesize. "\r\n";
$header[] = "User-Agent: UserAgent 1.0";
$header[] = "Connection: Keep-Alive";
$header[] = "Authorization: Basic ".$auth;
$header[] = "host: www.example.com";


$Response = httpsPost($url, $xml_data, $header);

echo $Response;

?>

サーバーから「Bad Request」を返します。助言がありますか?

4

3 に答える 3

2

私の最初の推測では、content-lengthヘッダーの後に余分な「\ r \ n」があると、サーバーは投稿コンテンツがそこから始まると見なします。また、念のため、「content-length」、「Content-type」、「host」を「Content-Length」、「Contnet-Type」、「Host」に変更します。

編集:それ、そしてロナルド・ブーマンの答え。

于 2009-12-22T08:27:13.110 に答える
2

私はあなたの議論が

curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data);

正しくありません。postfieldsオプションは、URLエンコードされた名前/値のペアである必要があります。ドキュメントから:

"これは、'para1 = val1&para2 = val2&...'のようなurlencoded文字列として、またはフィールド名をキーとして、フィールドデータを値として持つ配列として渡すことができます。valueが配列の場合、Content-Typeヘッダーは次のようになります。 multipart/form-dataに設定"

http://php.net/manual/en/function.curl-setopt.phpを参照してください

于 2009-12-22T08:31:41.220 に答える