Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php CRULASPX过帐问题_Php_Asp.net_Curl - Fatal编程技术网

Php CRULASPX过帐问题

Php CRULASPX过帐问题,php,asp.net,curl,Php,Asp.net,Curl,我一直在为www.pool.com开发php curl脚本 我可以处理viewstate和事件问题,但我看到了关于发布的其他问题 Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %>

我一直在为www.pool.com开发php curl脚本

我可以处理viewstate和事件问题,但我看到了关于发布的其他问题

Invalid postback or callback argument.  Event validation is enabled using 
<pages enableEventValidation="true"/> in configuration or <%@ Page
EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies
that arguments to postback or callback events originate from the server control that 
originally rendered them.  If the data is valid and expected, use the 
ClientScriptManager.RegisterForEventValidation method in order to register the postback or
callback data for validation.
在第一部分中,我得到了eventtarget、viewstate和eventvalidation,一切正常。然后我通过发布代码中的EventTargety单击高级搜索。也很好。但是,我正在发布另一个名为ctlback_Search1:txtKeyWordCharacters的数据,它给我的错误是无效回发

我不明白为什么它有错误

代码:

<?php

$url = "http://www.pool.com/viewlist.aspx";
$ckfile = tempnam("/tmp", "CURLCOOKIE");
$useragent = 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.2 (KHTML, like Gecko) Chrome/5.0.342.3 Safari/533.2';

$f = fopen('log.txt', 'w'); // file to write request header for debug purpose

/**
Get __VIEWSTATE & __EVENTVALIDATION
 */
$event = 'CtlBucket_Search1$lbtSearchToggleAdv';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);

$html = curl_exec($ch);

curl_close($ch);

preg_match('~<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="(.*?)" />~', $html, $viewstate);
preg_match('~<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="(.*?)" />~', $html, $eventValidation);

$viewstate = $viewstate[1];
$eventValidation = $eventValidation[1];



/**
 * Start Posting process
 */
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_STDERR, $f);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);

// Collecting all POST fields
$postfields = array();
$postfields['__EVENTTARGET'] = $event;
$postfields['__EVENTARGUMENT'] = "";
$postfields['__VIEWSTATE'] = $viewstate;
$postfields['__EVENTVALIDATION'] = $eventValidation;
// Problem is below
$postfields['CtlBucket_Search1:txtKeyWordCharacters'] = 4;

curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$ret = curl_exec($ch); // Get result after login page.
在数组$postfields上使用http_build_查询函数。它将做两件事。1它将使用普通过帐当前您正在进行多部分/表格数据过帐。2它将对数组中的值进行urlencode

curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postfields));

我用另一个preg_匹配解决了这个问题,因为每个会话的VIEWSTATE和EVENTVALIDATION都会改变。