zoukankan      html  css  js  c++  java
  • C#.net模拟提交表单POST

    方法一、
    System.Net.WebClient WebClientObj        = new System.Net.WebClient();
       System.Collections.Specialized.NameValueCollection PostVars  = new System.Collections.Specialized.NameValueCollection();
       PostVars.Add("A1","0");
       PostVars.Add("A2","0");
       PostVars.Add("A3","000");

       try
       {
        byte[] byRemoteInfo   = WebClientObj.UploadValues("http://www.lovezhao.com/vote.asp","POST",PostVars);
        //下面都没用啦,就上面一句话就可以了
        string sRemoteInfo   = System.Text.Encoding.Default.GetString(byRemoteInfo); 
        //这是获取返回信息
        richTextBox_instr.Text  += sRemoteInfo;
       }
       catch
       {}



    方法二、
    string url = "网址";
    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
    string s = "要提交的数据";
    byte[] requestBytes = System.Text.Encoding.ASCII.GetBytes (LoginInfo);
    req.Method = "POST";
    req.ContentType = "application/x-www-form-urlencoded";
    req.ContentLength = requestBytes.Length;
    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.Default);
    string backstr = sr.ReadToEnd(); Response.Write(line); sr.Close(); res.Close();
  • 相关阅读:
    visual studio 2010设置
    Win7 x64 PL/SQL 连接 Oralce 提示 Could not initialize "%ORACLE_HOME%\bin\oci.dll"
    jxl导入/导出excel
    struts2的action与jsp之间传递参数
    web服务器、容器和中间件
    myeclipse trial expired 注册码解决办法(可用于8.5)
    Java中的内部类
    JS的trim()方法
    struts2 <s:property>用法
    EL表达式的使用
  • 原文地址:https://www.cnblogs.com/goody9807/p/1246050.html
Copyright © 2011-2022 走看看