我不得不尝试处理表单html的随机名称和值,以便通过curl发布数据。
这是我的代码。
function grapvalue($html){
//parse content to grap name and value random
}
$opt = array(
CURLOPT_AUTOREFERER => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_COOKIEFILE => 'cookie.txt',
CURLOPT_COOKIEJAR => 'cookie.txt'
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => grapvalue($html)
)
$init = curl_init("site.com")
curl_setopt_array($init,$opt)
$html = curl_exec($init)我必须执行函数curl_exec ()两次,首先我必须执行curl_exec函数来检索html,以获得名称和随机值,然后发送数据。我该如何解决这个问题?
发布于 2011-06-08 02:04:09
以下是完整的解决方案:
//First, we make a request to grab the variables
function grapvalue(){
$opt = array(
CURLOPT_AUTOREFERER => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_COOKIEFILE => 'cookie.txt',
CURLOPT_COOKIEJAR => 'cookie.txt'
);
$init = curl_init("site.com");
curl_setopt_array($init,$opt);
$html = curl_exec($init);
//parse content to grap name and value random
}
//Than, just call grapvalue() without any parameters
$opt = array(
CURLOPT_AUTOREFERER => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_COOKIEFILE => 'cookie.txt',
CURLOPT_COOKIEJAR => 'cookie.txt'
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => grapvalue()
);
$init = curl_init("site.com");
curl_setopt_array($init,$opt);
$html = curl_exec($init);提示:与CURLOPT_COOKIEFILE和CURLOPT_COOKIEJAR__相比,您可能更喜欢使用CURLOPT_COOKIE。
发布于 2011-06-08 00:49:05
为什么不创建一个function cURL(),调用函数,获取$html,然后使用post值再次调用呢?
https://stackoverflow.com/questions/6268655
复制相似问题