2012-06-25 28 views

回答

2

您可以使用WebClientHttpWebRequest類使Web請求並獲得響應。

這裏是如何提出請求並得到響應

WebClient client = new WebClient(); 
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted); 
client.DownloadStringAsync(new Uri("http://someurl", UriKind.Absolute)); 

和異步響應處理程序是在這裏

void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) 
{ 
    var response= e.Result; // Response obtained from the web service 
} 

上面的例子適用於任何Web服務的示例代碼(也可能是PHP或JSP或ASP等)。

所有你需要做的是作出正確的請求和處理響應

+1

我會建議你使用HttpWebRequest的,因爲Web客戶端將通過URL命中和URL限制爲1024個字符。所以你必須通過使用POST HTTP動詞來使用HTTPWebRequest。 –

相關問題