![](/img/trans.png)
[英]How to know if i am successfully connected to my outgoing number in Android?
[英]How do I know if I have successfully connected to the URL I opened a connection with?
要檢查我是否可以連接到web-app命名服務,我打開與其地址的連接。如何檢查是否已連接到此URL /服務 ? 我正在考慮發送某種狀態方法(當客戶端嘗試打開與此URL的連接時),該方法確定客戶端是否能夠建立與服務的成功連接。 但是我該怎么做?
我正在嘗試這樣的事情:
final URL url = new URL("http://localhost:8084/service/index.jsp");
final URLConnection urlc = url.openConnection();
InputStream response = urlc.getInputStream();
// Now call a method in the service app that sends a status method...
// .....or can I get away with this ?
我建議
URL url = new URL("http://stackoverflow.com/questions/13775103/how-do-i-know-if-i-have-successfully-connected-to-the-url-i-opened-a-connection");
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
System.out.println(conn.getResponseCode());
它打印200
(OK)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.