I have the following code:
var Instance = WebRequest.Create(new Uri("http://mywebsite.com/page.aspx"));
var Data = new Dictionary<string, string>();
Data["Foo"] = "Bar";
Data["Baz"] = "Paz";
How can I submit GET request with the data?
I have the following code:
var Instance = WebRequest.Create(new Uri("http://mywebsite.com/page.aspx"));
var Data = new Dictionary<string, string>();
Data["Foo"] = "Bar";
Data["Baz"] = "Paz";
How can I submit GET request with the data?
When using GET
method, you should put your data into the the url.
var Data = new Dictionary<string, string>();
Data["Foo"] = "Bar";
Data["Baz"] = "Paz";
UriBuilder uri = new UriBuilder("http://mywebsite.com/page.aspx");
uri.Query = String.Join("&",Data.Select(x=>String.Format("{0}={1}",
x.Key, HttpUtility.UrlEncode(x.Value))));
var Instance = WebRequest.Create(uri.ToString());
Your url will be:
http://mywebsite.com:80/page.aspx?Foo=Bar&Baz=Paz