简体   繁体   English

使用Java将参数传递到YQL

[英]Passing parameters to YQL using Java

I am using the following code: 我正在使用以下代码:

String zip = "75227";
String str = "http://query.yahooapis.com/v1/public/yql?q=select%20Title%2C%20Address%2C%20" +
            "City%2C%20State%2C%20Phone%2C%20Distance%20from%20local.search%20where%20query%3D%22" +
            "food%20pantries%22%20and%20zip%3D%22" + zip +"%22%20and%20(category%3D%2296927050%22%20or" +
            "%20category%3D%2296934498%22)%20%7C%20sort(field%3D%22Distance%22)";

Document doc = Jsoup.connect(str).get(); 

and it is producing the results I want by replacing the zip code value. 它通过替换邮政编码值来产生我想要的结果。 I would like to also change the location. 我也想更改位置。 I tried doing the same I did with the zip code by doing this: 我尝试通过执行与邮政编码相同的操作:

String zip = "32207";

String service = "food pantry";

String testOne = "http://query.yahooapis.com/v1/public/yql?q=select%20Title%2C%20Address%2C%20" +
            "City%2C%20State%2C%20Phone%2C%20Distance%20from%20local.search%20where%20query%3D%22" +
            service + "%22%20and%20zip%3D%22" + zip +"%22%20and%20(category%3D%2296927050%22%20or" +
            "%20category%3D%2296934498%22)%20%7C%20sort(field%3D%22Distance%22)";

When used this way the variable "service" gave me an error. 使用这种方式时,变量“ service”给了我一个错误。

I initially tried to use the yql table like this: 我最初尝试使用yql表,如下所示:

String search = "http://query.yahooapis.com/v1/public/yql?q=";
String table = "select Title, Address, City, State, Phone, Distance from local.search where " +
            "query=\"food pantries\" and zip=\"75227\" and (category=\"96927050\" or category=" +
            "\"96934498\") | sort(field=\"Distance\")";

String searchText = search + table;

UPDATE: 更新:

Here is the error I am getting: 这是我得到的错误:

Exception in thread "main" org.jsoup.HttpStatusException: HTTP error fetching URL. Status=505, URL=http://query.yahooapis.com/v1/public/yql?q=select%20Title%2C%20Address%2C%20City%2C%20State%2C%20Phone%2C%20Distance%20from%20local.search%20where%20query%3D%22food pantry%22%20and%20zip%3D%2232207%22%20and%20(category%3D%2296927050%22%20or%20category%3D%2296934498%22)%20%7C%20sort(field%3D%22Distance%22)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:418)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:393)
at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:159)
at org.jsoup.helper.HttpConnection.get(HttpConnection.java:148)
at org.jsoup.examples.HtmlToPlainText.main(HtmlToPlainText.java:86)

However, this did not work either. 但是,这也不起作用。 Any ideas on how I can do this search and provide the service and zip code as variables? 关于如何进行搜索并将服务和邮政编码作为变量提供的任何想法?

Have you tried replacing String service = "food pantry"; 您是否尝试过替换String service = "food pantry"; with String service = "food%20pantry"; 使用String service = "food%20pantry"; ?

EDIT: 编辑:

and it is "food pantry" or "food pantries"... ? 它是“食品储藏室”还是“食品储藏室” ...?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM