你的位置:首页 > ASP.net教程

[ASP.net教程]如何调用外部的Web API


  1. Uri uri = new Uri(url + "?" + postData);  
  2.             System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(uri);  
  3.             request.Method = "GET";  
  4.             request.ContentType = "application/x-www-form-urlencoded";  
  5.             request.AllowAutoRedirect = false;  
  6.             request.Timeout = 5000;  
  7.             System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();  
  8.             Stream responseStream = response.GetResponseStream();  
  9.             StreamReader readStream = new StreamReader(responseStream, System.Text.Encoding.UTF8);  
  10.             string retext = readStream.ReadToEnd().ToString();  
  11.             readStream.Close();  
  12.             return retext;  
  13.