我有一个使用curl使用我的邮件/密码登录页面的脚本。 在此之前我需要解析一个字段以捕获一个值以将其发送到post请求中,但是在帖子之前的页面获取中我看不到字段:
<input id="X-Tmx-session-id" type="hidden" name="X-Tmx-session-id" value="ANY">
可以在浏览器中看到它。 问题是什么?
这是我的实际代码:
<?php
error_reporting(E_ALL);
Class WalMart{
var $http_response;
var $username;
var $password;
var $cookie;
var $post_payload;
var $uri;
var $re;
function __construct($username, $password){
$this->username = (string) $username;
$this->password = (string) $password;
$this->cookie = '[WALLMART_COOKIES].txt';
$this->re = "#name=\"X-Tmx-session-id\" value=\"(.*?)\">#";
}
function get(){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->uri);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:32.0) Gecko/20100101 Firefox/32.0');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_MAXREDIRS, 0);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookie);
$this->http_response = curl_exec($ch);
}
function parse_params(){
$this->uri = 'https://www2.walmart.com.br/login?continue=https://connect.walmart.com.br/connect/authorize?response_type=code&redirect_uri=https://api-ws.walmart.com.br/api/webstore/auth/callback&client_id=walmart_webstore';
$this->get();
// Dont work bcause input X-Tmx-session don't exists in the response string $this->http_response
if(preg_match($this->re, $this->http_response, $match)){
var_dump($match);
}
// FIELD <input id="X-Tmx-session-id" type="hidden" name="X-Tmx-session-id" value="ANY"> Don't exists in curl request
var_dump($this->http_response);
}
function start(){
$this->parse_params();
/*
* post_payload creation after parse params to post request
*
*/
}
}
$walmart = new WalMart('my_mail', 'password');
$walmart->start();
发送标头的问题?还是需要附加字段?
先谢谢。