HttpClient request payload post请求

https://blog.csdn.net/hhooong/article/details/52750647

//获取订单详情需要的传递的参数
String paramsOrder = "{\"hotelRange\": \"1\", \"lstChannelSourceType\": [1, 4], \"languageTypeEnum\": \"LANG_ZH\"}";
//发包形式获取订单详情
String orderDetail = post(httclient, "https://www.plateno.com/api/order/queryOrderList", paramsOrder, buffer.toString().replaceAll("path=/,", "").replaceAll("path=/", "").replace("; ;", ";"));

封装post

/**
     *参数为PayLoad形式的参数请求 
     */
    public String post(HttpClient httpClient, String url, String str, String cookie) throws ParseException, IOException{
        PostMethod post = new PostMethod(url);
        post.setRequestHeader("Accept", "application/json, text/plain, */*");
        post.setRequestHeader("Accept-Encoding", "gzip, deflate, br");
        post.setRequestHeader("Accept-Language", "zh-CN,zh;q=0.9");
        post.setRequestHeader("Connection", "keep-alive");
        post.setRequestHeader("Host", "www.plateno.com");
        post.setRequestHeader("Cookie", cookie);
        post.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
        post.setRequestHeader("Origin", "https://www.plateno.com");
        post.setRequestHeader("Referer", "https://www.plateno.com/Club/MemberInfo/");
        post.setRequestHeader("User-Agent","Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.75 Safari/537.36");
        RequestEntity entity = new StringRequestEntity(str, "application/json;charset=UTF-8", "utf-8");
        post.setRequestEntity(entity);
        httpClient.executeMethod(post);
        String result = post.getResponseBodyAsString();
        return result;
    }

 

posted on 2019-06-05 17:25  大山008  阅读(762)  评论(0)    收藏  举报