C# 调用 HTTPWebRequest 实现简单Get请求

3,762 views次阅读
一条评论

 

 

C#学了两天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;
}
}

 

 

Swaggy Macro
版权声明:本站原创文章,由 Swaggy Macro 2018-05-29发表,共计908字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(一条评论)
验证码
载入中...
2018-06-17 01:01:30 回复

[blockquote]签到成功!签到时间:上午1:01:18,每日打卡,生活更精彩哦~[/blockquote]