views:

132

answers:

5

I am using asp.net mvc and I want to fake a http post to see what would happen. Is there any software that I can use?

+7  A: 

I believe that Fiddler allows you to do this, plus a whole lot more.

I only use it for reviewing what's going to/from the server when dealing with AJAX induced headaches, but I'm fairly sure you can use it to re-issue HTTP requests both as they were originally and modified, which should fit the bill for you.

Rob
You believe correctly. There is indeed.
Jon Hanna
+1  A: 

I like TamperData, a Firefox addon.

bowenl2
+2  A: 
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();
Timothy Lee Russell
A: 

Here is some javascript for you:

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);
}
Pete Amundson
Or you could do the same thing with JQuery: `$.post(url, data, callback)`. :-) http://api.jquery.com/jQuery.post/
Ryan
damn jQuery...always stealing my JavaScript-foo :)
Pete Amundson
A: 

Charles has the ability to capture any http requests and responses and allows you to save sessions and edit/repeat them with easy. Worth a try and see if it's to your liking.

theburningmonk