public string GetWebRequestStringBearer(string postUrl, string paramData, Encoding dataEncode)
{
string ret = string.Empty;
try
{
//byte[] byteArray = dataEncode.GetBytes(paramData); //转化
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(postUrl));
webReq.Method = "GET";
//webReq.ContentType = "application/x-www-form-urlencoded";
webReq.ContentType = "application/json";
webReq.Headers.Add("Authorization", "Bearer " + paramData);
//webReq.ContentLength = byteArray.Length;
//Stream newStream = webReq.GetRequestStream();
//newStream.Write(byteArray, 0, byteArray.Length);//写入参数
//newStream.Close();
HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
ret = sr.ReadToEnd();
sr.Close();
response.Close();
//newStream.Close();
}
catch (Exception ex)
{
}
finally
{
}
return ret;
}
本文链接:https://my.lmcjl.com/post/978.html
4 评论