我有以下代码:
var Instance = WebRequest.Create(new Uri("http://mywebsite.com/page.aspx"));
var Data = new Dictionary<string, string>();
Data["Foo"] = "Bar";
Data["Baz"] = "Paz";
如何提交带有数据的 GET 请求?
我有以下代码:
var Instance = WebRequest.Create(new Uri("http://mywebsite.com/page.aspx"));
var Data = new Dictionary<string, string>();
Data["Foo"] = "Bar";
Data["Baz"] = "Paz";
如何提交带有数据的 GET 请求?
使用GET
方法时,您应该将数据放入 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());
您的网址将是:
http://mywebsite.com:80/page.aspx?Foo=Bar&Baz=Paz