zoukankan      html  css  js  c++  java
  • winform调用http

    一、post请求实现  

    
    
    public static string PostHttp(string url, string jsonParmaData)
            {
                HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
                try
                {
                    
                    NetworkCredential auth = new NetworkCredential("admin", "www.hd123.com");//添加此代码
    
                    var postData = Encoding.UTF8.GetBytes(jsonParmaData);
                    httpWebRequest.ContentType = "application/json";
                    httpWebRequest.Method = "POST";
                    httpWebRequest.Timeout = 10000;
                    httpWebRequest.AutomaticDecompression = DecompressionMethods.GZip;
                    httpWebRequest.Credentials = auth;//添加认证
    
                    httpWebRequest.ContentLength = postData.Length;
                    httpWebRequest.GetRequestStream().Write(postData, 0, postData.Length);
                    HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                  
     using (Stream stream = httpWebResponse.GetResponseStream()) 
    { 
    
    
    using (StreamReader sr = new StreamReader(stream, Encoding.UTF8)) 
    { string str = sr.ReadToEnd(); 
    sr.Close(); 
    stream.Close(); 
    httpWebResponse.Close(); 
    return str;
     }
    
    }
     
    } catch (Exception ex)
     {
       try { httpWebRequest.Abort(); } catch { } 
    } 
    return null;
    
     } 
     
    View Code
    
    
    
     
  • 相关阅读:
    响应式开发
    webstrom配置
    CSS水平垂直居中
    CSS3里的 转换与过渡动效
    CSS布局
    CSS定宽居中的实现方案
    Flex布局篇2
    编辑器中快速生成代码——emmet输入法
    display:flex实践加感悟
    websocket connet.js
  • 原文地址:https://www.cnblogs.com/musexiaoluo/p/7148528.html
Copyright © 2011-2022 走看看