zoukankan      html  css  js  c++  java
  • ASP.NET 抓取网页内容-Post 数据

    在抓取网页时,有时候,需要将某些数据通过 Post 的方式发送到服务器,将以下代码添加在网页抓取的程序中,以实现将用户名和密码 Post 到服务器:

    string data = "userName=admin&passwd=admin888";
    byte[] requestBuffer = System.Text.Encoding.GetEncoding("gb2312").GetBytes(data);
     
    request.Method = "POST";
    request.ContentType = "application/x-www-form-urlencoded";
    request.ContentLength = requestBuffer.Length;
    using (Stream requestStream = request.GetRequestStream())
    {
        requestStream.Write(requestBuffer, 0, requestBuffer.Length);
        requestStream.Close();
    }
     
    using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("gb2312")))
    {
        string str = reader.ReadToEnd();
        reader.Close();
    }

    以上是以编码 gb2312 为例。

  • 相关阅读:
    LG P4284 [SHOI2014]概率充电器
    LG P2592 [ZJOI2008]生日聚会
    LG P4953 [USACO02FEB]Cow Cycling
    LG P2389 电脑班的裁员
    LG P2344 [USACO11FEB]Generic Cow Protests G
    前端简历
    前端面试题目
    大前端的技术栈
    前端 -为什么要清楚浮动?
    Redis的功能实现
  • 原文地址:https://www.cnblogs.com/ghfsusan/p/1613594.html
Copyright © 2011-2022 走看看