发送请求获取响应内容
Posted dinghanhua
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了发送请求获取响应内容相关的知识,希望对你有一定的参考价值。
C#请求url,获取响应的脚本
public string ResultOfApi(string url) { //发送请求 HttpWebRequest request = null; HttpWebResponse response = null; request = (HttpWebRequest)HttpWebRequest.Create(url); request.Method = "Get"; request.ContentType = "application / x - www - form - urlencoded"; request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (Khtml, like Gecko) Chrome/67.0.3396.99 Safari/537.36"; request.Accept = "text / html,application / xhtml + xml,application / xml; q = 0.9,image / webp,image / apng,*/*;q=0.8"; request.KeepAlive = true; //获取响应 response = (HttpWebResponse)request.GetResponse(); Stream S = response.GetResponseStream(); StreamReader streamreader = new StreamReader(S); string result = streamreader.ReadToEnd(); return result }
以上是关于发送请求获取响应内容的主要内容,如果未能解决你的问题,请参考以下文章
IT兄弟连 JavaWeb教程 使用AJAX发送POST请求并获取响应