开发者

Web Client Upload Values

开发者 https://www.devze.com 2023-01-31 18:00 出处:网络
I want to make a desktop application that enters a value in textbox and performs button actions for example design an application that enters value in google search box at google.comand performs act开

I want to make a desktop application that enters a value in textbox and performs button actions for example design an application that enters value in google search box at google.com and performs act开发者_如何学Pythonion as when any one presses search button i wrote a code but it threw exception The remote server returned an error: (405) Method Not Allowed.

WebClient wc = new WebClient();
string uri = "http://google.com";

NameValueCollection nvc = new NameValueCollection();

nvc.Add("search", "afnan");            

byte[] response = wc.UploadValues(uri, nvc);
textBox1.Text=Encoding.ASCII.GetString(response);


UploadValues is trying to do a POST (by default, at least; some other verbs are allowed, but they essentially still treat it as a body payload). It sounds like you just want a GET query like http://www.google.com/search?q=afnan - so just url-encode "afnan". Note, however, that you should always observe the target site's Terms and Conditions - in particular section 5:

You specifically agree not to access (or attempt to access) any of the Services through any automated means (including use of scripts or web crawlers)

If you do this, expect to get black-listed.

0

精彩评论

暂无评论...
验证码 换一张
取 消