0

PHP curl を使用して Tesco Mobile にログインしようとしています。次のコードがあります。

$postData='user=XXX&password=XXXXX';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://paymonthly.tescomobile.com/orderentry/LoginSubmit.do');
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, TRUE); 
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); 
curl_setopt ($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_REFERER, 'https://paymonthly.tescomobile.com/orderentry/LoginSubmit.do');
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);     
$result = curl_exec ($ch); 
curl_close($ch);

しかし、失敗しました。これを達成する方法を誰か助けてください。以下の Live HTTP からの出力を見つけてください。

前もって感謝します。

https://paymonthly.tescomobile.com/orderentry/LoginSubmit.do

POST /orderentry/LoginSubmit.do HTTP/1.1 ホスト: paymonthly.tescomobile.com ユーザーエージェント: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:18.0) Gecko/20100101 Firefox/18.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 リファラー: https://paymonthly.tescomobile.com/ orderentry/LoginSubmit.do;jsessionid=60af415cd448d5728a9fa98cdf99 Cookie: JSESSIONID=60af415cd448d5728a9fa98cdf99; reevoomark_marker=349049566; reevoo_ utma=1.324660794.1360800582.1360800582.1360800582.1; reevoo _utmb=1.5.6.1360800582; reevoo_utmc =1; リーブー_utmz=1.1360800582.1.1.utmgclid=CK6Vp5nBtLUCFeXKtAodVGIAVA|utmccn=(%20setではない)|utmcmd=(%20setではない)|utmctr=tescomobile; reevoomark_bh_session=0af0a16fc00f5fbc8b0d28c571721a72; CUSTOMER_UUID=04fdc3e6-59e1-4038-81b7-ec7c5d63c9d4; __utma=152930744.490151867.1360800710.1360800710.1360800710.1; __utmb=152930744; __utmc=152930744; __utmz=152930744.1360800710.1.1.utmccn=(紹介)|utmcsr=phone-shop.tesco.com|utmcct=/tesco-mobile/my-tesco-mobile/|utmcmd=紹介 接続: キープアライブ コンテンツ タイプ: アプリケーション/ x-www-form-urlencoded Content-Length: 32 user=dinoc83&password=c079378643 HTTP/1.1 200 OK X-Powered-By: JSP/2.1 サーバー: Sun GlassFish Enterprise Server v2.1.1 Content-Type: text/html;charset= UTF-8 Transfer-Encoding: チャンク日付:

2013 年 2 月 14 日(木)00:15:27 GMT

4

4 に答える 4

2

変更してみてください: $postData='user=XXX&password=XXXXX';

$postData=array('user=XXX&password=XXXXX');

http://php.net/manual/en/function.curl-setopt.phpにいくつかのコード サンプルがあります。

よろしく、

于 2013-02-14T11:47:13.383 に答える
0

$postData次の方法で値を設定することもできます。

$postData = array( 'user'=>'XXX', 'password'=>'XXXX' );

そして、何に注意してください:

配列を CURLOPT_POSTFIELDS に渡すとデータが multipart/form-data としてエンコードされ、URL エンコードされた文字列を渡すとデータが application/x-www-form-urlencoded としてエンコードされます。

于 2013-02-14T12:19:30.587 に答える
0

この方法でこれを試してみてください。別のサーバーにデータを投稿するために機能しています

   $postData='user=XXX&password=XXXXX'
   $url ="https://paymonthly.tescomobile.com/orderentry/LoginSubmit.do";
   $ch = curl_init() or die(curl_error()); 
    curl_setopt($ch, CURLOPT_POST,1); 
    curl_setopt($ch, CURLOPT_POSTFIELDS,$postData); 
    curl_setopt($ch, CURLOPT_URL,$url);// here the request is sent to payment gateway 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    $result=curl_exec($ch) or die(curl_error());

    curl_close($ch);
于 2013-02-14T11:43:59.763 に答える
0

フォームを確認したところ

フォーム属性アクションにはパラメーター jsessionidがあります。コードでは使用しません。最初にフォームを含むページをロードしてから、応答コードを解析し、投稿用の正しい URL を取得する必要があると思います。そして、これは Cookie を初期化する必要があります。

于 2013-02-14T11:51:14.853 に答える