阅读背景:

C#使用WebRequest调用WebApi的方法

来源:互联网 

1:Get: 

public static string HttpGetJsonAPI(string uri) { try { HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(uri); webRequest.Method = "GET"; webRequest.ContentType = "application/json"; webRequest.Accept = "application/json"; webRequest.Headers.Add("Authorization", GlobalVariable.NowLoginUser.JwtKey); HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse(); StreamReader reader = new StreamReader(webResponse.GetResponseStream(), Encoding.UTF8); String res = reader.ReadToEnd(); reader.Close(); return res.Trim(); } catch (Exception ex) { return null; } } public static string HttpGetJsonAPI(string



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: