using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Xml;
using System.Security.Cryptography;
using System.Net;
using System.IO;
public partial class Manager400_Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// var ip = "123.138.20.245";
// var seed = "asdfghjkl";
// var accountno = "********";
// var pwd = "******";
// var url = "http://" + ip + "/interface/queryagentinfo.php?accountno=" + accountno + "&pwd=" +
// GetMD5(GetMD5(pwd) + seed + DateTime.Now.AddMinutes(1).ToString("yyyy-MM-dd HH:mm")) + "&seed=" +
// seed + "&cno=&gno=";
//
// var reStr = WebPost(url, "");
// Response.Write(reStr);
Manager400DAL dal = new Manager400DAL();
dal.GetALLFromWeb();
}
private string WebPost(string action, string postString, int ReTry = 1)
{
if (ReTry > 1)
{
return null;
}
var encoding = Encoding.GetEncoding("utf-8");
var data = encoding.GetBytes(postString);
var myRequest = (HttpWebRequest)WebRequest.Create(action);
myRequest.Method = "POST";
myRequest.Timeout = 40000;
myRequest.ContentType = "application/x-www-form-urlencoded"; //"application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
//myRequest.KeepAlive = true;
try
{
var newStream = myRequest.GetRequestStream();
Response.Write("-----------");
newStream.Write(data, 0, data.Length);
newStream.Close();
}
catch
{
Response.Write("链接NC失败,正在重试(" + ReTry + "/" + 1 + ")");
return WebPost(action, postString, ++ReTry);
}
try
{
var result = myRequest.GetResponse();
var receiveStream = result.GetResponseStream();
var sr = new StreamReader(receiveStream);
var ResponseString = sr.ReadToEnd();
sr.Close();
sr.Dispose();
return ResponseString;
}
catch
{
Response.Write("接收返回信息失败,正在重试(" + ReTry + "/" + 1 + ")");
return WebPost(action, postString, ++ReTry);
}
}
public static string GetMD5(string Str)
{
var md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
var bytes = System.Text.Encoding.UTF8.GetBytes(Str);
bytes = md5.ComputeHash(bytes);
md5.Clear();
var re = "";
for (var i = 0; i < bytes.Length; i++)
{
re += bytes[i].ToString("x").PadLeft(2, '0');
}
return re;
}
}