zoukankan      html  css  js  c++  java
  • post 数据

    //post数据得到返回值

    public string PostJsonToFenghuang(string postUrl, string referUrl, string data)
    {

    string result = "";
    try
    {
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(postUrl);
    request.Accept = "text/plain, */*; q=0.01";
    request.Referer = referUrl;
    request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E)";
    request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
    request.Method = "POST";
    request.KeepAlive = true;
    request.AllowAutoRedirect = true;
    request.Headers.Add("Accept-Encoding", "gzip, deflate");
    Stream postStream = request.GetRequestStream();
    byte[] postData = Encoding.UTF8.GetBytes(data);
    postStream.Write(postData, 0, postData.Length);
    postStream.Dispose();
    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    if (response.ContentEncoding == "gzip")
    {
    MemoryStream ms = new MemoryStream();
    GZipStream zip = new GZipStream(response.GetResponseStream(), CompressionMode.Decompress);
    byte[] buffer = new byte[1024];
    int l = zip.Read(buffer, 0, buffer.Length);
    while (l > 0)
    {
    ms.Write(buffer, 0, l);
    l = zip.Read(buffer, 0, buffer.Length);
    }
    ms.Dispose();
    zip.Dispose();
    result = Encoding.UTF8.GetString(ms.ToArray());
    }
    else
    {
    Stream respStream = response.GetResponseStream();
    StreamReader RespStreamReader = new StreamReader(respStream, Encoding.UTF8);
    result = RespStreamReader.ReadToEnd();
    }
    return result;
    }
    catch (Exception)
    {
    throw;
    }

    }

  • 相关阅读:
    JQuery中的事件与动画
    JQuery选择器
    初识JQuery
    JavaScript对象及初识面向对象
    JavaScript操作DOM对象
    JavaScript操作BOM对象
    JavaScript基础
    文件管理2
    文件管理
    创建线程
  • 原文地址:https://www.cnblogs.com/yyangjing/p/9554122.html
Copyright © 2011-2022 走看看