0
我想通過https連接從服務器獲取xml。如果我用curl命令做它Android java.net.UnknownHostException:主機無法解析:server_address:443
curl -k -A "Mozilla/4.0" https://username:[email protected]/test/infoxml.ashx
連接是成功的,但是當我在android上嘗試java時,它不起作用。我使用此代碼:
URL url = new URL("https://user:[email protected]");
HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Authorization", "Basic **********************");
conn.setRequestProperty("User-Agent", "Mozilla/4.0");
conn.setRequestProperty("Host", "server.com");
conn.setRequestProperty("Accept", "*/*");
InputStream content = conn.getInputStream();
正如你所看到的,我設置了標題根據工作curl命令的詳細輸出,主要內容如下:
* About to connect() to server.com port 443 (#0)
* Trying (server ip)... connected
* Connected to server.com (server ip) port 443 (#0)
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using AES256-SHA
* Server certificate:
* subject: C=SI; ST=City; L=City; O=Company d.d; OU=ES; CN=server.com
* start date: 2010-02-05 00:00:00 GMT
* expire date: 2011-02-02 23:59:59 GMT
* common name: server.com (matched)
* issuer: C=ZA; ST=Western Cape; L=Cape Town; O=Thawte Consulting cc; OU=Certification Services Division; CN=Thawte Premium Server CA; emailAddress=censored
* SSL certificate verify ok.
* Server auth using Basic with user 'username'
> GET /test/infoxml.ashx HTTP/1.1
> Authorization: Basic ****************************
> User-Agent: Mozilla/4.0
> Host: server.com
> Accept: */*
>
< HTTP/1.1 200 OK
< Connection: Keep-Alive
< X-Powered-By: ASP.NET
< X-AspNet-Version: 2.0.50727
< Keep-Alive: timeout=5, max=100
< Server: Microsoft-IIS/6.0
< Cache-Control: private
< Set-Cookie: JSESSIONID=abcs8ebwPsf-A-biM7KTs; path=/
< Content-Type: text/xml; charset=utf-8
< Content-Length: 1688
< Date: Thu, 30 Sep 2010 23:16:06 GMT
<
* Connection #0 to host server.com left intact
* Closing connection #0
* SSLv3, TLS alert, Client hello (1):
<?xml version="1.0"...
我是新來的這安全連接的東西,所以容易對我:)
ps對不起,我的英語不好。
試過這一個,沒有運氣...它拋出「的java.net.UnknownHostException:https://server.com」異常.. – Alen 2010-10-01 10:33:06
它可以讓你與你的真實服務器異常?我假設「server.com」不是您的域名。 – Brian 2010-10-01 15:38:29
我正在爲Android編寫一個小部件應用程序,它連接到移動運營商服務並返回一些信息。不,server.com絕對不是真正的域名。 – Alen 2010-10-01 17:32:58