• C#后台请求其它网站页面


    /// <summary>
    /// 指定Post地址使用Get 方式获取全部字符串
    /// </summary>
    /// <param name="url">请求后台地址</param>
    /// <returns></returns>
    public string RequestPost(string url, string builder)
    {
    string result = "";
    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
    req.Method = "POST";
    req.ContentType = "application/x-www-form-urlencoded";
    //req.ContentType = "text/json";
    #region 添加Post 参数
    //StringBuilder builder = new StringBuilder();
    //int i = 0;
    //foreach (var item in dic)
    //{
    // if (i > 0)
    // builder.Append("&");
    // builder.AppendFormat("{0}={1}", item.Key, item.Value);
    // i++;
    //}
    byte[] data = Encoding.UTF8.GetBytes(builder);
    req.ContentLength = data.Length;
    using (Stream reqStream = req.GetRequestStream())
    {
    reqStream.Write(data, 0, data.Length);
    reqStream.Close();
    }
    #endregion
    HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
    Stream stream = resp.GetResponseStream();
    //获取响应内容
    using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
    {
    result = reader.ReadToEnd();
    }
    return result;
    }
    }

  • 相关阅读:
    用jQuery写的一个简单的弹出窗口(IE7\IE8\FF3)
    live write test
    sql2
    查询所有表索引
    java初学问题记录(2012.02.092012.02.16)
    SQL
    centso7网卡bond
    vmware模板
    Dockerfile参考
    Docker简单介绍
  • 原文地址:https://www.cnblogs.com/liwp/p/6972921.html
Copyright © 2020-2023  润新知