zoukankan      html  css  js  c++  java
  • C# Get 带body

                try
                {
                    //System.GC.Collect();
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
                    request.Proxy = null;
                    request.KeepAlive = false;
                    request.Method = "GET";
                    request.ContentType = "application/json; charset=UTF-8";
                    request.AutomaticDecompression = DecompressionMethods.GZip;
                    string Data = "{"CorpId":"300014"}";
                    //if (Data != "")
                    //{
                        var type = request.GetType();
                        var currentMethod = type.GetProperty("CurrentMethod", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(request);
                        var methodType = currentMethod.GetType();
                        methodType.GetField("ContentBodyNotAllowed", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(currentMethod, false);
    
                        using (var streamWriter = new StreamWriter(request.GetRequestStream()))
                        {
                            streamWriter.Write(Data);
                        }
                    //}
    
                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                    Stream myResponseStream = response.GetResponseStream();
                    StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.UTF8);
                    string retString = myStreamReader.ReadToEnd();
    
                    myStreamReader.Close();
                    myResponseStream.Close();
    
                    if (response != null)
                    {
                        response.Close();
                    }
                    if (request != null)
                    {
                        request.Abort();
                    }
    
                    return retString;
                }
                catch (Exception ex)
                {
                    return ("ERROR:" + ex.Message + ":::" + ex.InnerException.Message);
                }
    
  • 相关阅读:
    Linux 安装SonarQube
    Linux 安装postgresql
    如何为chrome浏览器设置socks5代理
    echarts tab切换宽度变为100px解决方案
    将url参数转为对象
    一行js代码实现时间戳转时间格式
    解决问题的方法论
    李笑来的幻灯课
    随便写写(最近更新于2021/07/18早)
    谈谈装系统这件事
  • 原文地址:https://www.cnblogs.com/wonder223/p/13853864.html
Copyright © 2011-2022 走看看