Marklogic 400错误请求 [英] Marklogic 400 Bad Request

查看:94
本文介绍了Marklogic 400错误请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我试图按照此处所述在REST Uri中使用StructuredQuery .
当我在Chrome中使用Postman并以以下方式请求查询URI时:


I trying to use StructuredQuery in REST Uri as documented here.
When I use Postman from Chrome and requesting query URI as:

http://IPADDRESS:PORT/v1/search?structuredQuery={"query":{"or-query":{"queries":[{"and-query":{"queries":[ {"word-constraint-query":{"constraint-name":"bio","text":["product"]}}, {"value-constraint-query":{"constraint-name":"company","text":["MarkLogic"]}} ]}}, {"and-query":{"queries":[ {"element-constraint-query":{"constraint-name":"spoken","and-query": {"queries":[{"term-query":{"text":["fie"]}}]} }}, {"word-constraint-query":{"constraint-name":"stagedir","text":["fall"]}}, {"value-constraint-query":{"constraint-name":"person","text":["GRUMIO"]}} ]}}, {"and-query":{"queries":[ {"properties-query":{"term-query":{"text":["fish"]}}}, {"directory-query":{"uri":["/images/2012/02/27/"]},"infinite":true} ]}}, {"and-query":{"queries":[ {"collection-query":{"uri":["mlw2012"]}}, {"term-query":{"text":["fun"]}} ]}}]}}}

给我答复.

现在,当我尝试使用Java来实现此功能时,使用HttpClient会给我400错误的请求错误,代码:

Now when I try to implement this in Java, using HttpClient it's giving me 400 Bad request error, Code:

CredentialsProvider credsProvider = new BasicCredentialsProvider();
query="http://192.168.192.110:8013/v1/search?structuredQuery=%7B%22query%22%3A%7B%22or-query%22%3A%7B%22queries%22%3A%5B%7B%22and-query%22%3A%7B%22queries%22%3A%5B%20%7B%22word-constraint-query%22%3A%7B%22constraint-name%22%3A%22bio%22%2C%22text%22%3A%5B%22product%22%5D%7D%7D%2C%20%7B%22value-constraint-query%22%3A%7B%22constraint-name%22%3A%22company%22%2C%22text%22%3A%5B%22MarkLogic%22%5D%7D%7D%20%5D%7D%7D%2C%20%7B%22and-query%22%3A%7B%22queries%22%3A%5B%20%7B%22element-constraint-query%22%3A%7B%22constraint-name%22%3A%22spoken%22%2C%22and-query%22%3A%20%7B%22queries%22%3A%5B%7B%22term-query%22%3A%7B%22text%22%3A%5B%22fie%22%5D%7D%7D%5D%7D%20%7D%7D%2C%20%7B%22word-constraint-query%22%3A%7B%22constraint-name%22%3A%22stagedir%22%2C%22text%22%3A%5B%22fall%22%5D%7D%7D%2C%20%7B%22value-constraint-query%22%3A%7B%22constraint-name%22%3A%22person%22%2C%22text%22%3A%5B%22GRUMIO%22%5D%7D%7D%20%5D%7D%7D%2C%20%7B%22and-query%22%3A%7B%22queries%22%3A%5B%20%7B%22properties-query%22%3A%7B%22term-query%22%3A%7B%22text%22%3A%5B%22fish%22%5D%7D%7D%7D%2C%20%7B%22directory-query%22%3A%7B%22uri%22%3A%5B%22%2Fimages%2F2012%2F02%2F27%2F%22%5D%7D%2C%22infinite%22%3Atrue%7D%20%5D%7D%7D%2C%20%7B%22and-query%22%3A%7B%22queries%22%3A%5B%20%7B%22collection-query%22%3A%7B%22uri%22%3A%5B%22mlw2012%22%5D%7D%7D%2C%20%7B%22term-query%22%3A%7B%22text%22%3A%5B%22fun%22%5D%7D%7D%20%5D%7D%7D%5D%7D%7D%7D"
    credsProvider.setCredentials(new AuthScope(IpAddress, port), new UsernamePasswordCredentials(user, password));

    DefaultHttpClient client = new DefaultHttpClient();
    client.setCredentialsProvider(credsProvider);

    HttpGet get = new HttpGet(query);
    ResponseHandler<String> handler = new BasicResponseHandler();
    HttpResponse resp = client.execute(get);

错误:

HTTP/1.1 400 Bad Request [Content-type: application/xml, Server: MarkLogic, Content-Length: 364, Connection: Keep-Alive, Keep-Alive: timeout=5]

我想念什么?

在此先感谢,
Prithvi.

Thanks in advance,
Prithvi.

推荐答案

如果打印出错误响应的正文,应该会给您更多信息.

If you print out the body of the error response, that should give you more information.

也就是说,您可能要考虑使用Java API,该Java API建立在Apache HttpClient和Jersey客户端之上,并为您处理HTTP交互.

That said, you might want to consider using the Java API, which is built on top of Apache HttpClient and Jersey Client and handles the HTTP interactions for you.

这篇关于Marklogic 400错误请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆