2014-10-27 63 views
0

我们有一个在asp.net中编程的搜索引擎。 因为我可以预测和卷曲或多或少有直接的联系,所以我设法解决个别结果。 但我无法控制结果列表,下面是它的工作原理:cURL和ASP.NET:发布参数问题

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

如果我尝试使用直接链接进入搜索页面,它不起作用,因为它不知道在哪个数据库中进行搜索。 我想看看在后的参数与萤火虫,我得到了以下几点:

Checkbox_db1 on 
__EVENTARGUMENT 
__EVENTTARGET LinkButtonCategory 
__VIEWSTATE zeyhbf5vg41g6a4f1ezragf136er46ga4gfv658a4r6g4 (something looking like that but longer) 

这是我尝试在卷曲:

$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不熟悉:/ 任何人都可以提供帮助吗?在此先感谢

+0

这需要时间,但我发现如何提取VIEWSTATE岗位。 – 2014-10-28 10:30:55

回答

0

所以,首先你得到一个普通的卷曲获得的初始页面。

然后你必须提取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);