Web Client Upload Values

12,534

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.

Share:
12,534
Afnan Bashir
Author by

Afnan Bashir

Starting Programming since was 14 and played with GW Basic......and was always motivated in becoming Computer Geek. By Interest learned Assembly language and programmed Micro controllers (ATMEGA,8051.PIC) I met C# in my graduation and since then stuck in that since then and I never loved anything else much. Currently learning Yii

Updated on June 27, 2022

Comments

  • Afnan Bashir
    Afnan Bashir almost 2 years

    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 action 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);