0

サラム

サーバーからいくつかの xml 応答を取得したい

ただし、このサーバーはxmlリクエストのみを受け入れます

私はこのコード例を持っています

  <?php

$url = "http://www.pj.ma/phonexmlfeeds";

$post_string = '<?xml version="1.0 encoding="UTF-8" ?><search_requests> <search_request id="req1"><content>statut=1 AND linguistic_expansion2(lingex_qui_quoi,1,0,"qui_quoi","Restaurant",LIN_EXACT|LIN_LEM0|LIN_LEM1|LIN_LEM2|LIN_SYN1|LIN_SYN2|LIN_PHO1|LIN_ORT)</content><code>sortBy(casanet_perfect(lingex_qui_quoi));filterBy(casanet_perfect_filter(lingex_qui_quoi));setSortAttribute(indice,sortDirection,sortDirectionDesc);sortBy(indice,score2(lingex_qui_quoi,lingex_ou,matrice), ordered(lingex_qui_quoi),ordered(lingex_ou),rs);catalogBy(libniv3);sendxref(rs);sendxref(crs);sendxref(nomcomm);sendxref(activite);sendxref(libniv3);sendxref(villep);sendxref(adrp);sendxref(nomvoie);sendxref(numtel_typetel);sendxref(internet);sendxref(pub);sendxref(marque);sendXrefHighlights();</code><options><option name="maxFiles">10</option><option name="startFiles">11</option><option name="highlight_zone_start">{match}</option><option name="highlight_zone_end">{/match}</option></options><metadata><meta name="base">Pages Jaunes</meta></metadata></search_request></search_requests>';


$header  = "POST /phonexmlfeeds HTTP/1.1";
$header  = "Connection: close";
$header .= "Content-Type: text/xml";
$header .= "User-Agent: Dalvik/1.4.0 (Linux; U; Android 2.3.3; GT-S5830 Build/GINGERBREAD)";
$header .= "Host: www.pj.ma"; 
$header .= "Content-Length: 1053";
$header .= "Accept-Encoding: gzip";
$header .= $post_string;

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header);

$data = curl_exec($ch); 

if(curl_errno($ch))
    print curl_error($ch);
else
    curl_close($ch);

echo $data;

?>

しかし、それはこの応答を返します

お使いのブラウザは、このサーバーが理解できないリクエストを送信しました。

ここに、wifisnifer によってキャプチャされたリクエストの例を投稿します

POST /phonexmlfeeds HTTP/1.1 接続: 閉じる コンテンツ タイプ: テキスト/xml ユーザー エージェント: Dalvik/1.4.0 (Linux; U; Android 2.3.3; GT-S5830 ビルド/GINGERBREAD) ホスト: www.pj.ma コンテンツ-長さ: 1052 Accept-Encoding: gzip

<?xml version="1.0 encoding="UTF-8" ?><search_requests> <search_request id="req1"><content>statut=1 AND linguistic_expansion2(lingex_qui_quoi,1,0,"qui_quoi","Restaurant",LIN_EXACT|LIN_LEM0|LIN_LEM1|LIN_LEM2|LIN_SYN1|LIN_SYN2|LIN_PHO1|LIN_ORT)</content><code>sortBy(casanet_perfect(lingex_qui_quoi));filterBy(casanet_perfect_filter(lingex_qui_quoi));setSortAttribute(indice,sortDirection,sortDirectionDesc);sortBy(indice,score2(lingex_qui_quoi,lingex_ou,matrice), ordered(lingex_qui_quoi),ordered(lingex_ou),rs);catalogBy(libniv3);sendxref(rs);sendxref(crs);sendxref(nomcomm);sendxref(activite);sendxref(libniv3);sendxref(villep);sendxref(adrp);sendxref(nomvoie);sendxref(numtel_typetel);sendxref(internet);sendxref(pub);sendxref(marque);sendXrefHighlights();</code><options><option name="maxFiles">10</option><option name="startFiles">1</option><option name="highlight_zone_start">{match}</option><option name="highlight_zone_end">{/match}</option></options><metadata><meta name="base">Pages Jaunes</meta></metadata></search_request></search_requests>
4

2 に答える 2

2

カスタム ヘッダーの場合は、改行 (\r\n) を追加します。

または、ヘッダーにhttp://us3.php.net/curl_setoptを使用することを検討してください。

curl_setopt($ch, CURLOPT_HTTPHEADERS, array(
    'POST /phonexmlfeeds HTTP/1.1',
    'Connection: close',
    'Content-Type: text/xml',
    etc...
    ));
于 2012-09-12T12:12:56.443 に答える
0

この行を編集します --

$header  .= "Connection: close";

あなたが持っているように--

$header  = "Connection: close";
于 2012-09-12T12:04:52.430 に答える