2010-12-20 100 views
2

我想製作一個桌面應用程序,在文本框中輸入一個值並執行按鈕操作,例如設計一個應用程序,該應用程序在google.com的google搜索框中輸入值並執行操作,就像任何人按下搜索按鈕我寫了一個代碼,但它拋出異常遠程服務器返回一個錯誤:(405)方法不允許。Web客戶端上傳值

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

回答

4

UploadValues試圖做一個POST(默認情況下,至少,一些其他的動詞是允許的,但他們本質上還是把它作爲一個機構的有效載荷)。它聽起來像你只是想GEThttp://www.google.com/search?q=afnan查詢 - 所以只是網址編碼"afnan"。但是請注意,你應該總是觀察目標站點的Terms and Conditions - 尤其是第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)

如果你這樣做,希望得到列入黑名單。

+0

我很榮幸能得到主持人的答覆謝謝sir.Let我谷歌,我會在一些家庭工作後給你找回 – 2010-12-20 21:59:10

+0

@afnan - 我也是一個普通的網站用戶;我戴了很多帽子。 – 2010-12-20 22:02:23

+0

和我工作的網站他們支持它,我的意思是他們有joomla woerpress等su的插件,他們允許這些操作 – 2010-12-20 22:04:22