引言
记录一下调用Web API的几种方式,以调用百度API为例.
HttpWebRequest
HttpWebRequest位于System.Net命名空间,是常用的调用Web API类库.
string strURL = "http://apis.baidu.com/apistore/weatherservice/citylist?cityname=" + HttpUtility.UrlEncode("北京"); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strURL); request.Method = "GET"; request.Headers.Add("apikey", "XXXXXXXXXXXXXXXXXXXXXXXXXX"); HttpWebResponse response