Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Programmatically Sending HttpRequests w/ GET or POST params

Status
Not open for further replies.

digiduck

Programmer
Apr 4, 2003
95
US
Ok, I'm writing a simple helper class for sending HttpWebRequests programmatically w/ the ability to optionally include GET or POST parameters. I thought I had it all done but I've run into a few problems...

First with sending GET params (I'm just cutting my code in snippets from my class so it may look like it isn't complete but that's because it isn't, at least not here):
Code:
this.request = (HttpWebRequest)WebRequest.Create(new Uri(url));
this.request.Method = "GET";
StreamWriter writer = new StreamWriter(this.request.GetRequestStream());
writer.Write("param1=value1&param2=value2");
writer.Close();

Now when I try and get the response w/
Code:
this.request.GetResponseStream();
it throws the error "Cannot send a content-body with this verb-type". Any help here?

Now for the POST params I use the same code as above except I set the
Code:
this.request.Method="GET";
to
Code:
this.request.Method="POST";
and here's the error I get for that... "The remove server returned an error: (405) Method Not Allowed". The error is slightly different depending on the URL I'm attempting to POST to but that's basically what they all say.

Any help would be greatly appreciated :D Thank you!

ud


tkc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top