C# 后台向一个url 发送请求
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C# 后台向一个url 发送请求相关的知识,希望对你有一定的参考价值。
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url );
request.Headers.Add("Authorization", (string)Newtonsoft.Json.JsonConvert.DeserializeObject(token));
request.ContentType = "application/json";
request.Referer = url;
request.Timeout = 30 * 1000;
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)";
request.Method = "GET";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
resultString = response.StatusCode.ToString();
Stream backStream = response.GetResponseStream();
StreamReader sr = new StreamReader(backStream, Encoding.GetEncoding("UTF-8"));
result = sr.ReadToEnd();
sr.Close();
backStream.Close();
response.Close();
request.Abort();
以上是关于C# 后台向一个url 发送请求的主要内容,如果未能解决你的问题,请参考以下文章
c# 后台GETPOSTPUTDELETE传输发送json数据
关于form表单或者Ajax向后台发送数据时,数据格式的探究
当用ajax,弹窗向后台发送请求时,如何查看是否被中间件阻止?