如何为HttpClient POST调用设置HttpEntity帖子主体

时间:2018-07-09 00:59:57

标签: post http-post httpclient

我需要一些帮助来弄清楚如何使用HttpClient发送http帖子。以下是我通过Postman应用程序发布内容的概述。

发布网址: https://someGslb.net:10322/createAccount

帖子正文: [{:databaseId“ 1234”:帐号Number“ 555555”     :phoneNumber“ 5551234567”}]

因此,如您所见,我需要在帖子正文中传递三个参数。但是这种格式,我以前从未使用过,因为我更熟悉JSON或XML格式来进行发布。有人可以帮我弄清楚如何将其放入Java代码的帖子中吗?现在,我有如下代码用于HttpClient设置,并且需要有关设置帖子正文参数的帮助。

            CloseableHttpClient httpClient = HttpClients.createDefault();
            HttpPost httpPost = new HttpPost(https://someGslb.net:10322/createAccount);

            httpPost.addHeader("X-external-caller", "myTeam");
            httpPost.addHeader("X-timeout-ms", "5000"));

            //This is where I need help.
            //How would I setup the post body for the above example.
            httpPost.setEntity(params);

            HttpResponse response =httpClient.execute(httpPost);

            System.out.println("Response=" + response.getStatusLine().getStatusCode());

0 个答案:

没有答案