2012-11-15 94 views
2

我試圖使用c + + Qt提出請求。
目標網站是http://www.artlebedev.ru/tools/decoder/advanced/
該網站看起來如此: enter image description here分析發佈請求

我用瀏覽器檢查它。
對我來說有一件奇怪的事情 - 標題中的隨機數字。
所以,我不確定我是否正確發送了發佈數據。

enter image description here

他們有什麼用的? 我讓我的請求,以便(如瀏覽器一樣):

postdata.append("accept:*/*&"); 
postdata.append("accept-charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3&"); 
postdata.append("Accept-Encoding:gzip,deflate,sdch&"); 
postdata.append("Accept-Language:en-US,en;q=0.8&"); 
postdata.append("Connection:keep-alive&"); 
postdata.append("Content-Length:36&"); 
postdata.append("Content-Type:application/x-www-form-urlencoded&"); 
postdata.append("Cookie:__utma=1.904416008.1352897318.1352905816.1352909441.3; __utmc=1; __utmz=1.1352897318.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __atuvc=7%7C46&"); 
postdata.append("Host:www.artlebedev.ru&"); 
postdata.append("Origin:http://www.artlebedev.ru&"); 
postdata.append("Referer:http://www.artlebedev.ru/tools/decoder/advanced/&"); 
postdata.append("User-Agent:Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11&"); 
postdata.append("X-Requested-With:XMLHttpRequest&"); 
postdata.append("random:0.9632773566991091&"); // I have no idea about this number 
postdata.append("Form Dataview URL encoded&"); 
postdata.append("csin:0&"); 
postdata.append("csout:0&"); 
postdata.append("text:fvddas&"); 
postdata.append("Decode:go"); 

我回答得網頁。但該網頁不包含已解碼的字符串。只有空洞的蜇傷。
它看起來是這樣的: enter image description here

這是我第一次提出要求,請幫我找出路。

回答

2

隨機值看起來像某種Cross-site request forgery令牌,以防止人們做你正在做的事情,但它實際上並未被使用。如果我使用Fiddler重新發出請求而沒有任何cookie或隨機值,請求仍然成功。

事實上,這一要求也做:

POST http://www.artlebedev.ru/tools/decoder/advanced/ HTTP/1.1 
Host: www.artlebedev.ru 
Content-Type: application/x-www-form-urlencoded 
Content-Length: 33 

csin=0&csout=0&text=foo&Decode=go 

所以一定有什麼不對您的要求,我想你不應該剛剛copypasted從外部觀察者進入代碼的請求,但看着在你正在做什麼:

postdata.append("Form Dataview URL encoded&"); 

這不是一個HTTP頭。服務器甚至沒有迴應400 Bad Request。該行應該包含一個CRLF,用於將頭文件與實體('request body')分開。

如果您在發送之前輸出postdata的內容,看看您是否可以看到錯誤,可能會證明它有用。

也許如果你喜歡網站可以做的編碼翻譯(或者它可以做的任何事情),你可以詢問網站的創建者是否有公開可用的API,或者他們甚至可以分享一些代碼或者指向有價值的資源,爲自己重新創建這樣的轉換。

+0

你打開了我的眼睛,尤其是提琴手是一個理解和看它如何工作的超級有用的工具。 – Tebe