C# 调用 HTTPWebRequest 实现简单Get请求
学了两天C#写了个快递查询,没有做Json解析。
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Net; using System.IO; namespace WindowsFormsApp4 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { MessageBox.Show ((Get(textBox1.Text))); } private string Get(string str) { HttpWebRequest macro = HttpWebRequest.Create(“http://www.kuaidi100.com/query?type=yunda&postid=“ + textBox1.Text) as HttpWebRequest; macro.Method = “GET”; macro.UserAgent = “Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36”; HttpWebResponse response = (HttpWebResponse)macro.GetResponse(); string res = new System.IO.StreamReader(response.GetResponseStream(), Encoding.GetEncoding(“utf-8”)).ReadToEnd(); return res; } }
原文链接:C# 调用 HTTPWebRequest 实现简单Get请求
Macro's Blog 版权所有,转载请注明出处。
[blockquote]签到成功!签到时间:上午1:01:18,每日打卡,生活更精彩哦~[/blockquote]