我正在使用Odata4j。当我尝试使用查询执行简单的 Web 搜索时,在代码的最后一行出现以下异常:
PS:如果您觉得有帮助,请投票。谢谢
java.lang.RuntimeException: Expected status OK, found Bad Request. Server response:
Parameter: Query is not of type String
at org.odata4j.jersey.consumer.ODataJerseyClient.doRequest(ODataJerseyClient.java:165)
这是我的代码:
ODataConsumer consumer = ODataConsumers
.newBuilder("https://api.datamarket.azure.com/Bing/Search/v1/")
.setClientBehaviors(OClientBehaviors.basicAuth("accountKey", "My account key here"))
.build();
System.out.println(consumer.getServiceRootUri()+consumer.toString());
OQueryRequest<OEntity> oQueryRequest = consumer.getEntities("Web").custom("Query", "Search text criteria");
System.out.println("oRequest"+oQueryRequest);
Enumerable<OEntity> entities = oQueryRequest.execute();
最佳答案
对 Java 的了解不多,但我刚刚在 Node.js 的实现中遇到了同样的错误,问题是我忘记在查询周围添加单引号。它应该是这样的:
...&Query='stackoverflow'
因此,在 URL 编码之后,我们得到如下内容:
...&Query=%27stackoverflow%27
至少这对我有用。
关于Azure Bing Web 搜索因查询搜索而失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24080298/