4

我有一个看起来像这样的 AQL 查询

items.find(
    {
        "path":{"$match":"product/*"},
        "size":{"$gt" : "10000"},
        "type":{"$eq" : "file"}

    }
)

我的 java HttpClient 看起来像这样

    String url = "http://restEndpoint/";
    HttpClient client = HttpClientBuilder.create().build();
    HttpPost request = new HttpPost(url);

    request.addHeader("User-Agent", USER_AGENT);
    request.addHeader("Content-Type", "text/plain");

   /*how do I insert the data here*/
    request.setEntity();

    HttpResponse response = client.execute(request);

我想知道如何在 request.setEntity 中插入查询,因为它只接受 HttpEntity

4

1 回答 1

4

看起来您正在使用 Apache httpcomponents。

有一个教程解释了如何使用实体

您可以使用各种实体类来包装您的内容,例如,对于字符串内容,您可以使用如下内容:

StringEntity myEntity = new StringEntity("important message", ContentType.create("text/plain", "UTF-8"));

只要确保您使用正确的 mimetype。

有关可用实体类的 javadoc 可在此处获得。

于 2017-02-24T11:39:41.533 回答