如何建立到localhost:8080的URL连接并检查HTTP响应代码是否介于200和209之间?(How to make a URL connection to localhost:8080 an

编程入门 行业动态 更新时间:2024-10-26 05:17:49
如何建立到localhost:8080的URL连接并检查HTTP响应代码是否介于200和209之间?(How to make a URL connection to localhost:8080 and check if the HTTP Response code is between 200 and 209? [closed])

我一直在努力为这个问题找到答案。

如何建立到localhost:8080的URL连接并检查HTTP响应代码是否介于200和209之间?

I have been struggling to get answer for this question.

How to make a URL connection to localhost:8080 and check if the HTTP Response code is between 200 and 209?

最满意答案

这应该这样做:

URL url = new URL("http://example.com"); HttpURLConnection connection = (HttpURLConnection)url.openConnection(); connection.setRequestMethod("GET"); connection.connect(); int code = connection.getResponseCode(); if (code>=200 && code <= 209){ //... }

This should do it:

URL url = new URL("http://example.com"); HttpURLConnection connection = (HttpURLConnection)url.openConnection(); connection.setRequestMethod("GET"); connection.connect(); int code = connection.getResponseCode(); if (code>=200 && code <= 209){ //... }

更多推荐

本文发布于:2023-08-07 22:32:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1466024.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:代码   HTTP   localhost   URL   Response

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!