java.net.UnknownHostException : 서버의 유효하지 않은 호스트 이름 : local
오류를 해결하기 위해 취해야 할 단계는 무엇입니까?
java.net.UnknownHostException: Invalid hostname for server: local
Android 에뮬레이터에 새로운 가상 호스트 이름을 추가했지만 결과는
java.net.UnknownHostException virtualhostname at
java.net.InetAddress.lookUpHostByName(InetAddress.java:506)
PC에 가상 호스트 URL을 입력하면 표시됩니다. 그런 다음 에뮬레이터에서 실행하고 Logcat을 확인할 때 200, 202 또는 오류 코드 번호 인 경우 HTTP 상태를 읽거나 확인할 수 없었습니다. 그것은 단순히UnknownHostException
실제로 예외는 "local"이라는 이름의 알려진 서버가 없다는 것입니다. 내 생각에 당신은 당신의 로컬 컴퓨터에 연결하려고합니다. 호스트 이름으로 시도 "localhost"
대신에, 혹은 127.0.0.1
나 ::1
(마지막에서 IPv6)입니다.
로부터 의 javadoc :
호스트의 IP 주소를 확인할 수 없음을 표시하기 위해 발생합니다.
127.0.0.1
나 ::1
또는 "localhost"
그 나는 정말 놀랄 것 작동하지 않습니다 그렇다면 항상 루프백 인터페이스해야합니다.
네트워크에 실제로 "local"이라는 서버가있는 경우 DNS 설정을 검사하거나 호스트 파일에 추가하십시오.
Mac에서도 같은 문제가 발생했습니다. $HOSTNAME
터미널에서 Ping을 수행 할 때 문제가 발생 하여 다시 돌아 왔습니다 ping: cannot resolve myHostName: Unknown host
.
해결하려면 :
- 수행
echo $HOSTNAME
터미널에. - 표시되는 호스트 이름이 무엇이든간에
myHostName
ping을 시도하십시오ping myHostName
. 반환되면 파일에ping: cannot resolve myHostName: Unknown host
항목을 추가/etc/hosts
하십시오. 해당 편집
/etc/hosts
파일을 위해 다음을 추가하십시오.127.0.0.1 myHostName
도움이 되길 바랍니다.
java.net.UnknownHostException : 호스트가 해결되지 않았습니다.
호스트의 IP 주소를 확인할 수 없음을 표시하기 위해 발생합니다.
이 예외는 유효한 Wi-Fi에 연결되어 있지만 라우터가 인터넷을받지 못하는 경우에도 발생합니다. 이것을 재현하는 것은 매우 쉽습니다.
- 유효한 와이파 이에 연결
- 라우터가 연결된 상태에서 라우터에서 케이블을 제거하십시오.
이 오류를 관찰 할 것입니다 !!
당신은 실제로 이것을 해결할 수 없습니다, 당신은 정상적으로 사용자에게 알릴 수 있습니다. (예 : "연결할 수 없습니다")
이것은 질문에 국한되지 않지만 언급 된에 대해 인터넷 검색을 할 때이 질문이 나타 났으며 UnknownHostException
다른 곳에서는 해결책을 찾을 수 없으므로 여기에 답변을 추가 할 것이라고 생각했습니다.
지속적으로 수신 된 예외는 다음과 같습니다.
java.net.UnknownHostException: google.com
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at java.net.Socket.connect(Socket.java:538)
at java.net.Socket.<init>(Socket.java:434)
at java.net.Socket.<init>(Socket.java:211)
...
유효한 호스트에 어떻게 연결을 시도하더라도 터미널에 인쇄해도 도움이되지 않습니다. 모든 것이 옳았습니다.
해결책
trim()
공백이 포함 된 호스트 문자열을 호출하지 않습니다 . 프록시 서버를 작성할 때 헤더 split(":")
에 세미콜론을 사용하여 HTTP 헤더에서 호스트를 얻습니다 HOST
. 이 왼쪽 공백 UnknownHostException
은 공백이있는 호스트가 유효한 호스트가되지 않도록합니다. 이렇게 host = host.trim()
온 것은 String host
모호한 문제를 해결했다.
이것은 여러 가지 이유로 발생할 수 있습니다
1) VPN이 연결되어 있는지 확인하십시오. 그렇다면 때때로이 오류가 발생할 수 있습니다
"호스트 이름, localhost가 루프백 주소 127.0.0.1로 확인됩니다 (대신 cscotun0에서 10.xxx.1.193 사용)"
2) $ HOSTNAME을 확인하십시오
3) 명령 행에서 $ HOSTNAME을 핑 (Ping)하려고 시도하고 작동하지 않으면 시스템 설정을 조정하여 로컬 호스트가 핑에 응답하도록하십시오.
Your hostname is missing. JBoss uses this environment variable ($HOSTNAME) when it connects to the server.
[root@xyz ~]# echo $HOSTNAME
xyz
[root@xyz ~]# ping $HOSTNAME
ping: unknown host xyz
[root@xyz ~]# hostname -f
hostname: Unknown host
There are dozens of things that can cause this. Please comment if you discover a new reason.
For a hack until you can permanently resolve this issue on your server, you can add a line to the end of your /etc/hosts file:
127.0.0.1 xyz.xxx.xxx.edu xyz
Try the following :
String url = "http://www.google.com/search?q=java";
URL urlObj = (URL)new URL(url.trim());
HttpURLConnection httpConn =
(HttpURLConnection)urlObj.openConnection();
httpConn.setRequestMethod("GET");
Integer rescode = httpConn.getResponseCode();
System.out.println(rescode);
Trim() the URL
Trying to connect to your local computer.try with the hostname "localhost" instead or perhaps ::/ - the last one is ipv6
Please try to set SPARK_LOCAL_IP environment variable to the ip address(can be localhost i.e. your own ip address) you want to connect. E.g.
$ export SPARK_LOCAL_IP=182.95.208.152
This way you will not be required to alter existing linux settings. Worked for me, hope helps you too.
Connect your mobile with different wifi connection with different service provider. I don't know the exact issue but i could not connect to server with a specific service provider but it work when i connected to other service provider. So try it!
I had this issue in my android app when grabbing an xml file the format of my link was not valid, I reformatted with the full url and it worked.
If your /etc/localhosts file has entry as below: Add hostname entry as below:
127.0.0.1 local host (add your hostname here)
::1 (add hostname here) (the last one is IPv6).
This should resolve the issue.
'IT story' 카테고리의 다른 글
Qt 프로그램을 종료하는 올바른 방법은 무엇입니까? (0) | 2020.07.22 |
---|---|
log4net 계층 및 로깅 수준 (0) | 2020.07.22 |
Pimpl 관용구 대 순수 가상 클래스 인터페이스 (0) | 2020.07.22 |
CoffeeScript를 사용하여 무언가를 반환하지 않는 방법이 있습니까? (0) | 2020.07.22 |
C ++ 컴파일러가이 조건부 부울 할당을 무조건 할당으로 최적화하지 않는 이유는 무엇입니까? (0) | 2020.07.22 |