1. 首先 创建出来webapi
2.加入调用的代码 如下 Get 的方法,把web api 的地址出入,例如 Of_GetStr("http://localhost:55457/api/default1/1");
public string Of_GetStr(string url)
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string ret = string.Empty;
Stream s;
string StrDate = "";
string strValue = "";
if (response.StatusCode == HttpStatusCode.OK)
{
s = response.GetResponseStream();
StreamReader Reader = new StreamReader(s, Encoding.UTF8);
while ((StrDate = Reader.ReadLine()) != null)
{
strValue += StrDate;
}
}
return strValue;
}