class Request {
private
const String host = "https://kop.kuaidihelp.com";
private
const String path = "/api";
private
const String requestMethod = "POST";
static
void Main(string[] args)
{
String querys = "";
String appId = "50001";
String method = "account.waybill.get";
String ts = GetTimeStamp() + "";
String appKey = "bdf3b5f50865ac813cbdfd6c9b572b79";
String signStr = appId + method + ts + appKey;
String sign = GetMd5(signStr, 32);
String bodys = "app_id=" + appId + "&method=" + method + "&ts=" + ts + "&sign=" + sign;
bodys = bodys + "&data={
"customer_name":"kuaibao888",
"customer_password":"1234567890",
"order_id":"KB101100111011232",
"trade_name":"智能手机",
"shipper_type":"sto",
"pay_type":"1",
"weight":"1.23",
"sender":{
"company":"南山区深圳软件产业基地",
"name":"张飞鸿",
"tel":"",
"mobile":"18688888888",
"province":"广东省",
"city":"深圳市",
"district":"南山区",
"address":"深圳软件产业基地"
},
"recipient":{
"company":"宝芝林贸易",
"name":"王三姨",
"tel":"95127777",
"mobile":"13666666666",
"province":"江苏省",
"city":"苏州市",
"district":"沧浪区",
"address":"人民路沧浪亭街31号宝芝林贸易有限公司"
}
}";
String url = host + path;
HttpWebRequest httpRequest = null;
HttpWebResponse httpResponse = null;
if (0 < querys.Length)
{
url = url + "?" + querys;
}
if (host.Contains("https://"))
{
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
}
else
{
httpRequest = (HttpWebRequest)WebRequest.Create(url);
}
httpRequest.Method = requestMethod;
httpRequest.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
if (0 < bodys.Length)
{
byte[] data = Encoding.UTF8.GetBytes(bodys);
using (Stream stream = httpRequest.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
}
try
{
httpResponse = (HttpWebResponse)httpRequest.GetResponse();
}
catch (WebException ex)
{
httpResponse = (HttpWebResponse)ex.Response;
}
Console.WriteLine(httpResponse.StatusCode);
Console.WriteLine(httpResponse.Method);
Console.WriteLine(httpResponse.Headers);
Stream st = httpResponse.GetResponseStream();
StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
Console.WriteLine(reader.ReadToEnd());
Console.WriteLine("\\n");
}
public
static
string GetMd5(string md5str, int type)
{
if (type == 16)
{
MD5 algorithm = MD5.Create();
byte[] data = algorithm.ComputeHash(Encoding.UTF8.GetBytes(md5str));
string sh1 = "";
for (int i = 0; i < data.Length; i++)
{
sh1 += data[i].ToString("x2").ToUpperInvariant();
}
return sh1.Substring(8, 16).ToLower();
}
else
if (type == 32)
{
MD5 algorithm = MD5.Create();
byte[] data = algorithm.ComputeHash(Encoding.UTF8.GetBytes(md5str));
string sh1 = "";
for (int i = 0; i < data.Length; i++)
{
sh1 += data[i].ToString("x2").ToUpperInvariant();
}
return sh1.ToLower();
}
return
"";
}
public
static
string GetTimeStamp()
{
TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
return Convert.ToInt64(ts.TotalSeconds).ToString();
}
public
static
bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
{
return
true;
}
}