Azure Bing Web 搜索因查询搜索而失败

标签 azure bing

我正在使用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/

相关文章:

python - 如何使用 Http 触发器和队列消息输出修复 Azure 函数 (Python) 测试错误

Azure AKS 自动缩放与所属缩放集自动缩放

PHP bing api html内容翻译响应显示为纯文本

windows-phone-7 - 无效的 appId 必应翻译 (WP7)

sql-server - 使用 Azure SQL Server 在其他表中插入

visual-studio - 如何将 EF 迁移应用到 Azure 中托管的数据库?

c# - 使用 Python SDK 按 RowKey 和 StartsWith 筛选 Azure 表存储

oauth - 如何使用 Bing 的搜索 API?

Android:必应图片搜索结果自定义

php - Bing Web Search API v7 似乎不起作用