zoukankan      html  css  js  c++  java
  • Asp.Net模拟post提交数据方法

    方法1:

            System.Net.WebClient WebClientObj = new System.Net.WebClient();
            System.Collections.Specialized.NameValueCollection PostVars = new System.Collections.Specialized.NameValueCollection();
            PostVars.Add("A1", "xxx");
            PostVars.Add("A2", "0");
            PostVars.Add("A3", "000");
    
            byte[] byRemoteInfo = WebClientObj.UploadValues("https://www.xxx.com", "POST", PostVars);
            string sRemoteInfo = System.Text.Encoding.Default.GetString(byRemoteInfo);
            Response.Write(sRemoteInfo);

    方法2:

    string url = "https://www.xxx.com/api/";
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
            string postdata = "key=djfkdjkf";
            byte[] requestBytes = System.Text.Encoding.UTF8.GetBytes(postdata);
            req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            req.ContentLength = requestBytes.Length;
            req.Referer = "https://www.xxx.com";
            Stream requestStream = req.GetRequestStream();
            requestStream.Write(requestBytes, 0, requestBytes.Length);
            requestStream.Close();
            HttpWebResponse res = (HttpWebResponse)req.GetResponse();
            StreamReader sr = new StreamReader(res.GetResponseStream(), System.Text.Encoding.UTF8);
            string backstr = sr.ReadToEnd();
            Response.Write(backstr); 
            sr.Close(); 
            res.Close();
  • 相关阅读:
    android 显示自定义视图对话框
    android为按钮事件进行监听过程
    实验三
    实验二
    实验一
    第五次作业
    第四次作业
    第三次作业
    第二次作业
    第一次作业
  • 原文地址:https://www.cnblogs.com/webapi/p/10344838.html
Copyright © 2011-2022 走看看