【发布时间】:2011-02-19 08:52:02
【问题描述】:
我试图向 ASP.NET 页面发送 ajax 查询。
算法:
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'));
而且它不起作用:(
关于在 PHP CURL 的帮助下向 ASP.NET 页面发送 ajax 请求有什么想法吗?
【问题讨论】:
标签: php javascript asp.net ajax curl