zoukankan      html  css  js  c++  java
  • 使用HttpClient向服务器发送restful post请求

    直接上代码:

    public class RestClient {
        public static void main(String[] args) {
            String url = "http://ip地址/api/User/GetToken";
            HttpClient client = new HttpClient();
         //POST方法 PostMethod method
    = new PostMethod(url);
         //传递参数 NameValuePair[] data
    = { new NameValuePair("UserName", "sinopec\xxxx"), new NameValuePair("Password", "xxxx") }; method.setRequestBody(data); try { int statusCode = client.executeMethod(method); if (statusCode == 200) { String strJson = method.getResponseBodyAsString(); System.out.println(strJson); // System.out.println(map.get("user").getUsername()); } } catch (HttpException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }
  • 相关阅读:
    11.10
    11.9
    11.8 总结
    11.7
    11.6
    日报10.6
    日报10.5
    每周总结-3
    日报10.4
    日报10.2
  • 原文地址:https://www.cnblogs.com/longshiyVip/p/5069601.html
Copyright © 2011-2022 走看看