簡體   English   中英

cURL aspx發布問題

[英]cURL aspx posting issue

我一直在為www.pool.com開發php curl腳本

我可以處理viewstate和event問題,但是我看到有關發布的其他問題。

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,這很好。然后我通過發布eventtarget(您可以在代碼中看到)單擊高級搜索 也可以 但是,我正在發布稱為CtlBucket_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_query函數。 它會做兩件事。 1)它將使用常規發布(當前您正在執行multipart/form-data發布。2)它將對數組中的值進行urlencode

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM