2012-04-08 14 views
-1

PHP-cURLスクリプトで次のリクエストを行います。PHP-cURL POSTリクエストによるxmlリクエストの方法

http://site5.way2sms.com/QuickContacts 
POST /QuickContacts HTTP/1.1 
Host: site5.way2sms.com 
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0 
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 
Accept-Language: en-us,en;q=0.5 
Accept-Encoding: gzip, deflate 
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 
Connection: keep-alive 
X-Requested-With: XMLHttpRequest 
Content-Type: application/x-www-form-urlencoded; charset=UTF-8 
Referer: http://site5.way2sms.com/Main.action?id=0CD36BD332A5C7AE77FDBA1CBDBFFBB6.w809 
Content-Length: 16 
gads=ID=e2cdae9b764355fa:T=1333862873:S=ALNI_MYvxochQ56ILMvBDr4oyyqCIDVn3w 
Pragma: no-cache 
Cache-Control: no-cache 
folder=DashBoard 
HTTP/1.1 200 OK 
Server: Apache-Coyote/1.1 
Content-Type: text/html 
Content-Length: 1901 
Date: Sun, 08 Apr 2012 06:07:52 GMT 
Connection: close        

返されるコンテンツはXML形式です。どのようにそれらを処理するには?

+1

はどこに疑問が私の愛するのですか? – Michelle

+0

上記の詳細を使用してPOSTリクエストを行いたいと思います。 – Alfred

+0

@ Alfred ...なぜあなたはそれをできないのですか?あなたはcURLをインストールする方法を知らないのですか?あなたはPHPを知らないのですか?あなたはPOSTのやり方を知らないのですか?あなたは投稿が何であるかを知らないのですか?あなたはヘッダーを送る方法を知らないのですか?これを絞って**具体的に**あなたの問題点を説明してください。 – Brad

答えて

1

URLへのポストリクエストを生成し、cURLを使用して返されたデータを取得する場合は、次の機能を使用できます。

function cURL($url, $header=NULL, $cookie=NULL, $p=NULL) 
{ 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_HEADER, $header); 
    curl_setopt($ch, CURLOPT_NOBODY, $header); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
    curl_setopt($ch, CURLOPT_COOKIE, $cookie); 
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
    if ($p) { 
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 
     curl_setopt($ch, CURLOPT_POST, 1); 
     curl_setopt($ch, CURLOPT_POSTFIELDS, $p); 
    } 
    $result = curl_exec($ch); 
    if ($result) { 
     return $result; 
    } else { 
     return curl_error($ch); 
    } 
    curl_close($ch); 
} 

と同様に、

$data = cURL("http://site5.way2sms.com/QuickContacts", NULL, NULL, array("post_var" => value, "another_post_var" => val2));