Php cURL和ASP.NET:post参数问题

Php cURL和ASP.NET:post参数问题,php,asp.net,curl,Php,Asp.net,Curl,我们有一个用asp.net编程的搜索引擎。 我设法对单个结果进行卷曲,因为它们或多或少有直接的联系,我可以预测和卷曲。 但我无法卷曲结果列表,下面是它的工作原理: 在搜索页面上,我们必须通过复选框菜单选择要搜索的数据库。 一旦我检查了我想要搜索的数据库,我点击“搜索”按钮,它会将我转到搜索页面,并考虑选择的数据库 如果我尝试使用直接链接进入搜索页面,它将不起作用,因为它不知道搜索将在哪个数据库中进行。 我尝试使用Firebug查看post参数,得到以下结果: Checkbox_db1 on _

我们有一个用asp.net编程的搜索引擎。 我设法对单个结果进行卷曲,因为它们或多或少有直接的联系,我可以预测和卷曲。 但我无法卷曲结果列表,下面是它的工作原理:

在搜索页面上,我们必须通过复选框菜单选择要搜索的数据库。 一旦我检查了我想要搜索的数据库,我点击“搜索”按钮,它会将我转到搜索页面,并考虑选择的数据库

如果我尝试使用直接链接进入搜索页面,它将不起作用,因为它不知道搜索将在哪个数据库中进行。 我尝试使用Firebug查看post参数,得到以下结果:

Checkbox_db1  on
__EVENTARGUMENT
__EVENTTARGET LinkButtonCategory
__VIEWSTATE zeyhbf5vg41g6a4f1ezragf136er46ga4gfv658a4r6g4 (something looking like that but longer)
以下是我在curl中尝试的内容:

$ch = curl_init();
$fields = array ('Checkbox_db1' => 'on', '__EVENTARGUMENT' => '', 
                 '__EVENTTARGET' => 'LinkButtonCategory', '__VIEWSTATE' => '');
$postvars = '';
foreach($fields as $key=>$value)
{
    $postvars .= $key.'='.$value.'&';
}
rtrim ($postvars, '&');

curl_setopt ($ch, CURLOPT_URL, "monsite.com/choosedb.aspx");
curl_setopt ($ch, CURLOPT_POST, count($fields));
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postvars);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);

$output1 = curl_exec($ch);

$fields2 = array ('TxtBox1' => 'value1', 'Txtbox2' => 'value2', '__EVENTARGUMENT' => '',
                 '__EVENTTARGET' => '', '__VIEWSTATE' => '');
$postvars = '';
foreach($fields2 as $key=>$value)
{
    $postvars .= $key.'='.$value.'&';
}
rtrim ($postvars, '&');

curl_setopt ($ch, CURLOPT_URL, "monsite.com/search.aspx");
curl_setopt ($ch, CURLOPT_POST, count($fields2));
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postvars);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);

$output2 = curl_exec($ch);
但这当然行不通。。。。问题是我对ASP.NET一点也不熟悉:/
有人能帮忙吗?提前感谢

因此,首先,您可以使用常规卷曲获取初始页面

然后必须提取VIEWSTATE参数:

$regexViewstate = '/__VIEWSTATE\" value=\"(.*)\"/i';

function regexExtract($text, $regex, $regs, $nthValue)
{
if (preg_match($regex, $text, $regs)) {
 $result = $regs[$nthValue];
}
else {
 $result = "";
}
return $result;
}

$viewstate = regexExtract($data,$regexViewstate,$regs,1);
你将组成你的新职位:

$postData = '__EVENTARGUMENT=&__EVENTTARGET=LinkButtonCategory&__VIEWSTATE=';
$postData .= rawurlencode($viewstate).'&TxtBox1=value1&TxtBox2=value2';

curl_setOpt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_URL, $urlLogin);   
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile);     

$output = curl_exec($ch);

这需要时间,但我找到了如何提取VIEWSTATE帖子。