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. TNS-12549问题分析及解决办法

    该服务器启动监听时候报错因为最后一句是Linux Error:No space left on device 因为是LINUX Error,所以可以到/var/log/messages里查看具体报错信 ...

  2. autocad视图汇报,像ppt那样汇报

    在大部分场景中,工程师可以用cad进行汇报,避免去做PPT,浪费时间,ppt一般都是用一次就丢弃.而工程师对于设计的中间汇报,或三维bim汇报,评审汇报,展示汇报等,都可以直接用cad软件,方法是用视 ...

  3. Android--仿1号店继续拖动查看图文详情——一个自定义的ViewGroup

    声明:源代码不是我写的,是网上的以为大神写的(地址给忘了),我拿过来以后呢,稍微改动了一下源码,使之符合了项目需求,再次特别感谢那位大牛,非常感谢. 是一个自定义布局,继承自ViewGroup pac ...

  4. word2vec前世今生

    word2vec前世今生 2013年,Google开源了一款用于词向量计算的工具--word2vec,引起了工业界和学术界的关注.首先,word2vec可以在百万数量级的词典和上亿的数据集上进行高效地 ...

  5. zabbix系列之安全

    https://blog.csdn.net/xiaoyu_0217/article/details/73500125 存在问题: 1)zabbix的Admin口令太弱或使用默认口令(Admin/zab ...

  6. orcl 如何快速删除表中百万或千万数据

    orcl 数据库表中数据达到上千万时,已经变的特别慢了,所以时不时需要清掉一部分数据. bqh8表中目前有10000000条数据,需要保留19条数据,其余全部清除掉. 以下为个人方法: 1.首先把需要 ...

  7. Windows 常识大全【all】

    解决电脑卡顿问题 电脑常见技巧大全 电脑运行命令CMD集锦 开启Windows 7系统的“上帝模式” Win7下设置护眼的电脑豆沙绿界面 零基础如何组装电脑?装机之家手把手教您电脑组装教程图解 [Ex ...

  8. sql点滴—mysql中查询表的信息

    mysql中查询表的信息 查询mysql表字段信息的sql语句 SHOW DATABASES //列出 MySQL Server 数据库. SHOW TABLES [FROM db_name] //列 ...

  9. 安装和配置Apache服务器(上)

    首先,安装软件分安装版和压缩版,压缩版也就是我们现在所说的绿色安装包.安装板和压缩版的区别就是,安装板在安装的时候就已经自动给你配置好环境,压缩版安装之后还要自己配置环境.自己配置环境也是有好处的,知 ...

  10. SDN2017 第二次实验作业

    安装floodlight 参考链接:http://www.sdnlab.com/19189.html 从github下载源码,并编译安装 $ sudo apt-get install build-es ...