zoukankan      html  css  js  c++  java
  • 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;
        }
    }
  • 相关阅读:
    Spark性能优化指南——基础篇
    spark精华面试题
    JVM性能调优总结
    Eclipse安装Hadoop插件配置Hadoop开发环境
    CPU高的解决方法
    Flume源码分析--转载
    Flume-ng的原理和使用--转载
    spark内核源码深度剖析(2)--Spark的三种提交模式
    java调用so文件
    爬取网页数据基础
  • 原文地址:https://www.cnblogs.com/xuhongfei/p/3421606.html
Copyright © 2011-2022 走看看