如何在REST调用中将millisec中的Datetime参数添加到Apache Httpclient jar的HTTPPost

时间:2019-01-25 14:39:22

标签: java-ee http-post apache-httpclient-4.x apache-commons-httpclient

我正在通过HTTPPost在millisec中发送Datetime,在服务器端,这些日期似乎无效。因此,我不得不在URL自身后面附加变通方法,并且起作用了。

        private HttpPost generateRequest() {
    HttpPost post = new HttpPost("https://XXXXXXXXX/myserverAPI");
    try {
        post.setHeader(new BasicHeader("Content-Type","application/json"));
        post.setHeader(new BasicHeader("appKey","xxxxxxxxxxxx"));
        post.setHeader(new BasicHeader("Accept", "application/json"));
        post.setParams(new Http);
        // Add additional header to getRequest which accepts application/xml data
        List<NameValuePair> postParameters = new ArrayList<NameValuePair>();
        postParameters.add(new BasicNameValuePair("timeStart", "1548362234143"));
        postParameters.add(new BasicNameValuePair("timeEnd", "1548364034143"));
        post.setEntity(new UrlEncodedFormEntity(postParameters));
    } catch (Exception e) {

        e.printStackTrace();
    }
    return post;
}

现在,如果我进行这些更改

HttpPost("https://XXXXXXXXX/myserverAPI?timeStart=1548362234143&timeEnd=1548364034143");
//post.setEntity(new UrlEncodedFormEntity(postParameters));

它按预期工作。 任何帮助表示赞赏。

0 个答案:

没有答案