• 400操作 示例


    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;
        }
    }
  • 相关阅读:
    spring+mybatis多数据源切换
    【linux环境下】RabbitMq的安装和监控插件安装
    Slurm远程登录Jupyter Notebook
    Google Colab 使用
    关于conda和jupyter使用
    关于给C盘扩容以及动态磁盘
    关于使用实验室服务器的GPU以及跑上TensorFlow代码
    一些更改的后端接口和代码
    MarkDown to PDF
    蜗牛慢慢爬 LeetCode 25. Reverse Nodes in k-Group [Difficulty: Hard]
  • 原文地址:https://www.cnblogs.com/xuhongfei/p/3421606.html
Copyright © 2020-2023  润新知