Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add query string to httpwebrequest

Tags:

c#

.net

I want to add some querystrings to httpwebrequest, however I cannot find any property? I remembered there is a QueryString dictionary which I can use before.

like image 322
user496949 Avatar asked Feb 18 '11 10:02

user496949


1 Answers

The best way to add a query string is as follows:

var targetUri = new Uri("http://www.example.org?queryString=a&b=c");
var webRequest = (HttpWebRequest)WebRequest.Create(targetUri);

var webRequestResponse = webRequest.GetResponse();

Remember: If you're using user input to construct the Uri, ensure that you validate it, escape it and don't trust it.

like image 102
Rob Avatar answered Oct 05 '22 11:10

Rob