【问题标题】:Azure Bing Web search fails with Query searchAzure Bing Web 搜索因查询搜索而失败
【发布时间】:2014-06-06 11:03:25
【问题描述】:

我正在使用 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();

【问题讨论】:

    标签: azure bing


    【解决方案1】:

    对 Java 的了解不多,但我在 Node.js 的实现中遇到了同样的错误,问题是我忘记在查询周围添加单引号。它应该是这样的:

    ...&Query='stackoverflow'
    

    所以在 URL 编码之后我们有类似的东西:

    ...&Query=%27stackoverflow%27
    

    至少这对我有用。

    【讨论】:

    • 顺便说一句,如果有人需要node.js的实现,你可以使用这个模块:www.npmjs.com/package/node-bing-api
    • 也适合我。谢谢!
    猜你喜欢
    • 2018-09-30
    • 1970-01-01
    • 1970-01-01
    • 2018-05-01
    • 2015-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-20
    相关资源
    最近更新 更多