2010-08-11 107 views
3

我使用的是asp.net mvc,我想僞造一個http post來查看會發生什麼。有沒有我可以使用的軟件?如何僞造Http post?

+4

這是單元測試? – jwsample 2010-08-11 22:06:29

回答

7

我相信Fiddler可以讓你做到這一點,再加上更多。

我只是在處理AJAX引發的問題時用它來檢查服務器上/服務器的內容,但我相當肯定你可以用它來重新發出HTTP請求,因爲它們最初是和修改的,它們應該適合你的賬單。

+0

你相信是對的。確實如此。 – 2010-08-11 22:48:41

1

我喜歡TamperData,一個Firefox插件。

2
string var1 = "Foo"; 
string var2 = "Bar"; 

ASCIIEncoding encoding = new ASCIIEncoding(); 
string post = "var1=" + var1 + "&var2=" + var2; 
byte[] bites = encoding.GetBytes(post); 

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://Url/PageToPostTo.aspx"); 
request.Method = "POST"; 
request.ContentType = "application/x-www-form-urlencoded"; 
request.ContentLength = bites.Length; 
Stream s = request.GetRequestStream(); 
s.Write(bites, 0, bites.Length); 
s.Close(); 
0

下面是一些JavaScript你:

function makeRequest(message,url,responseFunction){ 
var http_request; 
    if (window.XMLHttpRequest){ // Mozilla, Safari,... 
    http_request = new XMLHttpRequest(); 
    if (http_request.overrideMimeType) { 
     // set type accordingly to anticipated content type 
     //http_request.overrideMimeType('text/xml'); 
     http_request.overrideMimeType('text/html'); 
    } 
} 
else if (window.ActiveXObject){ // IE 
    try { 
     http_request = new ActiveXObject("Msxml2.XMLHTTP"); 
    } catch (e){ 
     try { 
      http_request = new ActiveXObject("Microsoft.XMLHTTP"); 
     } catch (e) {} 
    } 
} 

http_request.onreadystatechange = responseFunction; 
    http_request.open("POST", url); 
http_request.setRequestHeader("Content-Type", "text/plain;charset=UTF-8"); 
http_request.send(message); 
} 
+0

或者你可以用JQuery做同樣的事情:'$ .post(url,data,callback)'。 :-) http://api.jquery.com/jQuery.post/ – Ryan 2010-08-12 04:06:41

+0

該死的jQuery ...總是偷我的JavaScript-foo :) – 2010-08-12 14:09:34

0

Charles有捕捉到任何HTTP請求和響應的能力,並允許您保存會話和編輯/方便贅述。值得一試,看看它是否符合你的喜好。