简体   繁体   English

cURL aspx发布问题

[英]cURL aspx posting issue

I have been developing php curl script for www.pool.com 我一直在为www.pool.com开发php curl脚本

I could handle viewstate and event problems but I see other issues about posting. 我可以处理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.

In first part , I'm getting eventtarget ,viewstate and eventvalidation and it's fine.Then I'm clicking advanced search through posting eventtarget(you can see in code). 在第一部分中,我获得了eventtarget,viewstate和eventvalidation,这很好。然后我通过发布eventtarget(您可以在代码中看到)单击高级搜索 It is also fine. 也可以 However, I'm posting other data which is called CtlBucket_Search1:txtKeyWordCharacters it gives me error invalid postback .. 但是,我正在发布称为CtlBucket_Search1:txtKeyWordCharacters的其他数据,它给我提供错误无效的回发..

I don't understand why it has error. 我不明白为什么会有错误。

Codes : 代码:

<?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.

Use http_build_query function over the array $postfields . 在数组$postfields使用http_build_query函数。 It will do two things. 它会做两件事。 1) it will use normal posting(currently your one is doing multipart/form-data posting. 2) it will do urlencode over the values from the array. 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