0

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?

Videron
  • 171
  • 1
  • 3
  • 11

1 Answers1

1

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
L.B
  • 114,136
  • 19
  • 178
  • 224