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;
}
}





版权声明:若无特殊注明,本文皆为《 Macro 》原创,转载请保留文章出处。
本文链接:C# 调用 HTTPWebRequest 实现简单Get请求 https://blog.julym.com/study/47.html
百度收录情况: 百度已收录,详情
正文到此结束

热门推荐

发表吐槽

你肿么看?

你还可以输入 250 / 250 个字

嘻嘻 大笑 可怜 吃惊 害羞 调皮 鄙视 示爱 大哭 开心 偷笑 嘘 奸笑 委屈 抱抱 愤怒 思考 日了狗 胜利 不高兴 阴险 乖 酷 滑稽

评论信息框

吃奶的力气提交吐槽中...

已有1条吐槽

Macro

2018-06-17 01:01 广东省佛山市电信
签到成功!签到时间:上午1:01:18,每日打卡,生活更精彩哦~
 Windows 10 x64   Google Chrome 55.0.2883.87