开发者

PHP Curl and ajax query to ASP.NET page

开发者 https://www.devze.com 2023-02-11 20:50 出处:网络
I trying to send ajax query to ASP.NET page. Algorithm: 1. I have form on my page; 2. When user filled all fields he clicks submit button;

I trying to send ajax query to ASP.NET page.

Algorithm:

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;

I know that my client side code is working perfectly but server side... This is code of server side:

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-for开发者_Python百科m-urlencoded; charset=utf-8', 'Connection: keep-alive'));
$Rec_Data = curl_exec($ch);
echo $Rec_Data;
die();

(request must imitate ajax request)

Result now:

1|#||4|58|pageRedirect||%2fGenericErrorPage.aspx%3faspxerrorpath%3d%2fDefault.aspx|

It seems like an error, coz normal result must give something like html-list.

I copied POST and Header data with help of httpfox.

i tried absolutely imitate my browser when my browser cookies was off:

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'));

And it's doesn't working :(

Any idea about sending ajax request to ASP.NET page with help of PHP CURL?


Sending requests to a Asp.Net page or a Asp.Net Webservice is no problem, there, where it is allowed. But it seems to me like you want to get the html content of an updatepanel. the security of asp net updatepanels is not unbreakable, but it is absolutly not designed to be copied from other websites. I never tried, but i think you will not reach your goal. Asp net is generating the viewstate, which is encrypted, and for an ajax request, it uses this viewstate to validate the request. You will not be able to reproduce this viewstate field, which is needed for making the updatepanel work.

0

精彩评论

暂无评论...
验证码 换一张
取 消