zoukankan      html  css  js  c++  java
  • C# post提交表单的例程

    protected string GetWebContent(string url)
        {
            Stream outstream 
    = null;
            Stream instream 
    = null;
            StreamReader sr 
    = null;
            HttpWebResponse response 
    = null;
            HttpWebRequest request 
    = null;
            
    // 要注意的这是这个编码方式,还有内容的Xml内容的编码方式
            Encoding encoding = Encoding.GetEncoding("GBK");
            
    byte[] data = encoding.GetBytes(url);

            
    // 准备请求,设置参数
            request = WebRequest.Create(url) as HttpWebRequest;
            request.Method 
    = "POST";
            
    //request.ContentType = "text/plain";
            request.ContentLength = data.Length;

            outstream 
    = request.GetRequestStream();
            outstream.Write(data, 
    0, data.Length);
            outstream.Flush();
            outstream.Close();
            
    //发送请求并获取相应回应数据

            response 
    = request.GetResponse() as HttpWebResponse;
            
    //直到request.GetResponse()程序才开始向目标网页发送Post请求
            instream = response.GetResponseStream();
            sr 
    = new StreamReader(instream, encoding);
            
    //返回结果网页(html)代码

            
    string content = sr.ReadToEnd();
            
    return content;
        }

  • 相关阅读:
    oracle(八)块清除
    oracle(七)索引
    oracle(六) physical read and logical read
    oracle动态视图(一)stat
    oracle(五)tkprof 使用 transient kernal profile 侧面 轮廓
    dbms_stats.gather_table_stats详解
    oracle(四) 常用语句
    oracle(三) SQL语句
    [Swift]LeetCode269. 外星人词典 $ Alien Dictionary
    [Mac]如何让两个窗口各占半个屏幕
  • 原文地址:https://www.cnblogs.com/hackpig/p/1668464.html
Copyright © 2011-2022 走看看