我試圖發送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 –