Azure Bing Web search fails with Query search

廉价感情. 提交于 2019-12-20 01:07:27

问题


I am using the Odata4j. When i try to execute for simple Web search with my query, getting following exeception at last line of the code:

PS: Please voteup if you find this helpful.Thanks

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) 

This is my code:

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();

回答1:


Not much into Java, but I've just got the same error with the implementation for Node.js, and the problem was that I forgot to add single quotes around the query. It should be something like:

...&Query='stackoverflow'

so after the URL encoding we have something like:

...&Query=%27stackoverflow%27

At least that worked for me.



来源:https://stackoverflow.com/questions/24080298/azure-bing-web-search-fails-with-query-search

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!