如何调用外部的Web API
Posted 快乐地编程
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何调用外部的Web API相关的知识,希望对你有一定的参考价值。
- Uri uri = new Uri(url + "?" + postData);
- System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(uri);
- request.Method = "GET";
- request.ContentType = "application/x-www-form-urlencoded";
- request.AllowAutoRedirect = false;
- request.Timeout = 5000;
- System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
- Stream responseStream = response.GetResponseStream();
- StreamReader readStream = new StreamReader(responseStream, System.Text.Encoding.UTF8);
- string retext = readStream.ReadToEnd().ToString();
- readStream.Close();
- return retext;
- }
以上是关于如何调用外部的Web API的主要内容,如果未能解决你的问题,请参考以下文章