我有一个看起来像这样的 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
最佳答案
看起来您正在使用 Apache httpcomponents。
有教程解释how to use entities .
您可以使用各种实体类来包装您的内容,例如对于字符串内容,你可以使用这样的东西:
StringEntity myEntity = new StringEntity("important message", ContentType.create("text/plain", "UTF-8"));
只需确保使用正确的 mimetype。
有关可用实体类的 javadoc 可用 here .
关于java HttpClient 发布文本/纯文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42020038/