简体   繁体   English

如何在字符串缓冲区输入循环之外获取http请求的输入流结果

[英]How can I get my inputstream result of a http request outside the string buffer input loop

I'm using openstreetmap I can only see the inputstream inside the while loop 我正在使用openstreetmap我只能在while循环中看到输入流

Here's my code inside the initialize of the javafx Controller: 这是我在javafx Controller的初始化中的代码:

try {
    URL myurl;
    myurl = new URL("https://nominatim.openstreetmap.org/search?q=The+White+House,+Washington+DC&format=json&addressdetails=1");
    URLConnection yc = myurl.openConnection();
    BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
    String inputLine;
    StringBuffer response = new StringBuffer();

    while ((inputLine = in.readLine()) != null)
                response.append(inputLine);

} catch (IOException ex) {
    Logger.getLogger(WeatherUpdateController.class.getName()).log(Level.SEVERE, null, ex);
}

I am trying to get the StringBuffer inside a string variable so I can search it. 我正在尝试将StringBuffer放入字符串变量中,以便进行搜索。

Use StringBuffer#toString() like so: 像这样使用StringBuffer#toString()

String str = response.toString();

Please note that you can use StringBuilder instead if you don't need synchronization. 请注意,如果不需要同步,则可以改用StringBuilder Source here 来源在这里

暂无
暂无

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

相关问题 如何获得字符串或输入流中的“原样”响应(格式)? - how can i get a response “AS IS” (format), in a string or in an inputstream? 码头:如何从请求中获取无缓冲的InputStream或Reader(通过HTTP“流”事件)? - Jetty: how do I get unbuffered InputStream or Reader from request (to “stream” events over HTTP)? 如何获得多维数组以字符串输入循环? - How can I get a multidimensional array to loop with string input? 如果http请求的内容类型为urlencoded,如何让我的spring启动控制器读取我对某个对象的http请求的主体? - How can I get my spring boot controller to read the body of my http request to an object if the http request has content type urlencoded? 如何获取HTTP请求数据? - How can I get the HTTP request data? 如何让我的输入验证工作,以便 -1 - 100 范围之外的任何内容都将显示错误消息? - How can I get my input validation to work so anything outside range -1 - 100 will display the error message? 如何获取InputStream以行作为String数组? - How do I get my InputStream to give me lines as a String array? 如何从java.lang.String获取java.io.InputStream? - How can I get a java.io.InputStream from a java.lang.String? Java如何在for循环之外获取一行Json数据 - Java how can I get a row of Json data outside of the for loop 我如何gzip一个InputStream并返回一个InputStream? - How can I gzip an InputStream and return an InputStream?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM