zoukankan      html  css  js  c++  java
  • .Net 请求Web接口Post和Get方法

    #region web服务请求 get post
    static string DefaultUserAgent = "www.zhiweiworld.com";
    public static String Get(string url)
    {
    System.Net.HttpWebRequest request = System.Net.WebRequest.Create(url) as System.Net.HttpWebRequest;
    request.Method = "GET";
    request.UserAgent = DefaultUserAgent;
    System.Net.HttpWebResponse result = request.GetResponse() as System.Net.HttpWebResponse;
    System.IO.StreamReader sr = new System.IO.StreamReader(result.GetResponseStream(), Encoding.UTF8);
    string strResult = sr.ReadToEnd();
    sr.Close();
    //Console.WriteLine(strResult);
    return strResult;
    }

    public static String Post(string url, System.Collections.Specialized.NameValueCollection para)
    {
    System.Net.WebClient WebClientObj = new System.Net.WebClient();

    byte[] byRemoteInfo = WebClientObj.UploadValues(url, "POST", para);//请求地址,传参方式,参数集合

    string rtContent = System.Text.Encoding.UTF8.GetString(byRemoteInfo);//获取返回值 
    return rtContent;
    }
    #endregion

  • 相关阅读:
    JSP内置对象和属性
    AWT和Swing
    Servlet的生命周期
    Servlet 与 CGI 的比较
    spring PROPAGATION
    JVM内存
    CISC, RISC 探究
    3.5.10 判断数字的奇偶
    java 中利用异或实现两个变量互换
    Java三大主流框架概述
  • 原文地址:https://www.cnblogs.com/zxtceq/p/7154378.html
Copyright © 2011-2022 走看看