我试图发送ajax查询到ASP.NET页面。PHP curl和ajax查询到ASP.NET页面
算法:
1. I have form on my page;
2. When user filled all fields he clicks submit button;
3. When submit button is clicked js send ajax request to page on my server (test.php)
4. test.php sends request to page on other server (ASP.NET). (page results in text/palin if right post fields was sended)
5. test.php echo result and js callback alert this result;
我知道,我的客户端代码可以正常使用,但服务器端... 这是服务器端的代码:
define('POSTURL', 'http://nakolesah.ru/');
define('POSTVARS', 'ctl00%24sm=ctl00%24contentPlaceHolder%24upnlFilterAuto%7Cctl00%24contentPlaceHolder%24ddlSizeVendorsAuto&__EVENTTARGET=ctl00%24contentPlaceHolder%24ddlSize...
$ch = curl_init(POSTURL);
curl_setopt($ch, CURLOPT_POST ,1);
curl_setopt($ch, CURLOPT_POSTFIELDS ,POSTVARS);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1);
curl_setopt($ch, CURLOPT_HEADER ,0); // DO NOT RETURN HTTP HEADERS
curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1); // RETURN THE CONTENTS OF THE CALL
curl_setopt($ch, CURLOPT_REFERER, POSTURL);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-Requested-With: XMLHttpRequest', 'X-MicrosoftAjax: Delta=true', 'Host: nakolesah.ru', 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Content-Type: application/x-www-form-urlencoded; charset=utf-8', 'Connection: keep-alive'));
$Rec_Data = curl_exec($ch);
echo $Rec_Data;
die();
(请求必须模仿Ajax请求现在)
结果:
1 |#|| 4 | 58 | pageRedirect ||%2fGenericErrorPage.aspx%3faspxerrorpath%3D%2fDefault.aspx |
这似乎是一个错误,因为正常的结果必须给像html-list这样的东西。
我在httpfox的帮助下复制了POST和Header数据。
我试图模仿绝对是我的浏览器时,我的浏览器的cookie被关:
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: nakolesah.ru',
'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; uk; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 WebMoney Advisor',
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language: uk,ru;q=0.8,en-us;q=0.5,en;q=0.3',
'Accept-Encoding: gzip,deflate',
'Accept-Charset: UTF-8,*',
'Keep-Alive: 115',
'Connection: keep-alive',
'X-Requested-With: XMLHttpRequest',
'X-MicrosoftAjax: Delta=true',
'Cache-Control: no-cache, no-cache',
'Content-Type: application/x-www-form-urlencoded; charset=utf-8',
'Pragma: no-cache'));
而且它不工作:(
任何想法有关发送Ajax请求到ASP.NET页面的帮助PHP CURL?
我达到了我的目标:)雅虎我很开心! POST变量中的参数存在问题。 – Mirgorod
哦不,这是错误的认为:(但是,在哪里生成事件状态和eventvalidation。在萤火虫的帮助下,我得到事件状态和eventvalidation的值,但这个值在窗体和后变量是不同的... – Mirgorod
默认情况下,它只有Base64编码,你可以在这里解码viewstates:http://ignatu.co.uk/ViewStateDecoder.aspx –