using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Web;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;
using System.Security.Cryptography;
namespace Test1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
} private void button1_Click(object sender, RoutedEventArgs e)
{
var mainUrl =
@"http://api.wap.guoguo-app.com/h5/mtop.cnwireless.cnlogisticdetailservice.wapquerylogisticpackagebymailno/1.0/";
var cookieUrl =
@"http://api.wap.guoguo-app.com/h5/mtop.cnwireless.cncainiaoappservice.getlogisticscompanylist/1.0/?v=1.0&api=mtop.cnwireless.CNCainiaoAppService.getLogisticsCompanyList&appKey=12574478&t=1496741493353&callback=mtopjsonp1&type=jsonp&sign=b0f7376271effd90e311f998ad3a3efb&data=%7B%22version%22%3A0%2C%22cptype%22%3A%22all%22%7D"; var mailNo = "826060403";//运单号码
//准备参数
var tikets = (DateTime.Now - Convert.ToDateTime("1970-01-01 00:00:00")).Ticks.ToString();
var cookie = GetCookie(cookieUrl);//先请求一次获得cookie,可以先缓存下来。
MessageBox.Show(cookie);
var key = new Regex(@"(?:^|;\s*)_m_h5_tk\=([^;]+)(?:;\s*|$)").Match(cookie).Value.Split('=')[1]
.Split('_')[0];
var sign = GetMD5Hash(key + "&" + tikets + "&12574478" + "&{\"mailNo\":\"" + mailNo + "\"}")
.ToLower(); //获得参数列表
var urlParas = string.Format(
"?v=1.0&api=mtop.cnwireless.CNLogisticDetailService.wapqueryLogisticPackageByMailNo&appKey=12574478&t={0}&callback=mtopjsonp&type=jsonp&sign={1}",
tikets, sign);
urlParas += "&data={\"mailNo\":\"" + mailNo + "\"}"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(mainUrl + urlParas);
request.Method = "GET";
request.Headers.Add("Cookie", cookie);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
string content = reader.ReadToEnd();
Console.WriteLine(content);
MessageBox.Show(content);
} //md5加密
public static string GetMD5Hash(String input)
{ // Use input string to calculate MD5 hash
MD5 md5 = System.Security.Cryptography.MD5.Create();
byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
byte[] hashBytes = md5.ComputeHash(inputBytes); // Convert the byte array to hexadecimal string
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hashBytes.Length; i++)
{
sb.Append(hashBytes[i].ToString("x2"));
// To force the hex string to lower-case letters instead of
// upper-case, use he following line instead:
// sb.Append(hashBytes[i].ToString("x2"));
}
return sb.ToString();
// return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(input, "md5"); } //获得cookie
public static string GetCookie(string url, int Timeout = 5000, bool isNeedProxy = true)
{
try
{ HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";
request.AllowAutoRedirect = false;
request.ContentType = "application/x-www-form-urlencoded;charset=gbk";
request.CookieContainer = new CookieContainer();
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11"; HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.Default);
string content = reader.ReadToEnd();
return response.Headers.Get("Set-Cookie");
}
catch (Exception ex)
{ return null;
}
} }
}

  

c# 菜鸟包裹查询的更多相关文章

  1. 【PE结构】由浅入深PE基础学习-菜鸟手动查询导出表、相对虚拟地址(RVA)与文件偏移地址转换(FOA)

    0 前言 此篇文章想写如何通过工具手查导出表.PE文件代码编程过程中的原理.文笔不是很好,内容也是查阅了很多的资料后整合出来的.希望借此加深对PE文件格式的理解,也希望可以对看雪论坛有所贡献.因为了解 ...

  2. asp.net linq查询环境搭建

    本文是以sqlserver2008为数据库,vs2013为开发工具来介绍的. 要搭建这样一个数据库的操作环境,首先建立一个类库项目 然后在这个类库项目中添加几个类:DBDataContext数据库上下 ...

  3. elasticsearch elk最全java api 搜索 聚合、嵌套查询

    目录 一. 一般查询... 2 (一) matchAllQuery(client). 2 (二) matchQuery(client);3 (三) multiMatchQuery(client);3 ...

  4. elasticsearch基本操作之--使用QueryBuilders进行查询

    /** * 系统环境: vm12 下的centos 7.2 * 当前安装版本: elasticsearch-2.4.0.tar.gz */ QueryBuilder 是es中提供的一个查询接口, 可以 ...

  5. WinForm操作隐藏的小知识点

    这次的项目需要使用Winform来实现,我们使用的是CSkin的皮肤.文章主要记录使用过程中遇到的小问题,也是楼主网上查找很久才找到的,这里总结下. 插件地址: 使用SKinDataGridView出 ...

  6. elasticsearch------java操作之QueryBuilders构建搜索Query

    版权声明:本文为非原创文章,出处:http://blog.csdn.net/xiaohulunb/article/details/37877435. elasticsearch 分布式搜索系列专栏:h ...

  7. VueJs 权限管理

    程序运行时,router只配置登陆 首页404 等基本页面 import Main from '@/views/Main.vue'; // 不作为Main组件的子页面展示的页面单独写,如下 expor ...

  8. SQL注入关联分析

    在Web攻防中,SQL注入绝对是一个技能的频繁项,为了技术的成熟化.自动化.智能化,我们有必要建立SQL注入与之相关典型技术之间的关联规则.在分析过程中,整个规则均围绕核心词进行直线展开,我们简单称之 ...

  9. 史上最全面的Elasticsearch使用指南

    Elasticsearch使用指南 Elasticsearch使用指南 前言 ES是什么 什么是全文检索 ES的应用场景 ES的存储结构 第一章:安装 1.下载 2.解压 3.配置 4.启动 5.查看 ...

随机推荐

  1. JS--我发现,原来你是这样的JS(引用类型不简单[下篇],基本包装类型与个体内置对象)

    一.介绍 本篇是续上一篇的,引用类型的下篇,本篇主要是说基本包装类型和个体内置对象.如果你能收获一些知识,那我很高兴,很满足,哈哈哈,希望大家能愉快看完.如果你想学好一门技术,要不忘初心,方得始终. ...

  2. 在web中如何调整上传过的图片方向 (exif)

    前提: 相机中拍的照片放到web上不会自动识别方向,如有些竖向显示的照片放到web上横向显示.这些照片在windows上是正确显示的.但是web不会自动旋转照片到正确方向.下面我们通过两种方法来实现这 ...

  3. Jboss7.1 local EJB lookup problem

    We are trying to lookup for an Local EJB in JBoss7.1, but we get an ClassCast Exception. This local ...

  4. 指定的 DSN 中,驱动程序和应用程序之间的体系结构不匹配

    在做通过 PL/SQL 导入Excel 数据的时候,在进行数据库连接的时候,选择DSN为Excel ,输入用户名和密码,进行Connect 出现错误“指定的 DSN 中,驱动程序和应用程序之间的体系结 ...

  5. Twain Capabilities 转

    转自:http://blog.csdn.net/pamxy/article/details/8629213 Asynchronous Device Events   异步设备事件 CAP_DEVICE ...

  6. SSH批量分发管理

    ssh服务认证类型主要有两个: 基于口令的安全验证: 基于口令的安全验证的方式就是大家一直在用的,只要知道服务器的ssh连接账户.口令.IP及开发的端口,默认22,就可以通过ssh客户端登陆到这台远程 ...

  7. Django之cookie&session

    cookie Cookie 是在 HTTP 协议下,服务器或脚本可以维护客户工作站上信息的一种方式.Cookie 是由 Web 服务器保存在用户浏览器(客户端)上的小文本文件,它可以包含有关用户的信息 ...

  8. 第 14 章 结构和其他数据形式(伸缩型数组成员C99)

    伸缩型数组成员C99 声明一个伸缩型数组成员的规则: 1.伸缩型数组成员必须是结构的最后一个成员: 2.结构中必须至少有一个成员: 3.伸缩数组的方括号是空的. 示例 struct flex { in ...

  9. 项目管理心经——正确的使用Microsoft Project

    第一步:填写task items 第二步:定义个性化日历(Tools-->Change working time) 第二步:填写task duration 第三步:填写前置任务 第四步:自动生成 ...

  10. [LOJ 2720][BZOJ 5417][UOJ 395][NOI 2018]你的名字

    [LOJ 2720][BZOJ 5417][UOJ 395][NOI 2018]你的名字 题意 给定一个大串 \(S\) 以及 \(q\) 次询问, 每次询问给定一个串 \(T\) 和区间 \([l, ...