2011-11-13 46 views
1

我必須編寫一個Android客戶端,我應該使用HttpComponents連接到端口8080上的特定服務器。 現在,我發現的所有內容都是Apache-網站,這是我所需要的幾乎完美,除了端口它連接到:HttpComponents - 連接到不同的端口

if (isSet) 
    { 
     throw new IOException("Hostname or Port are not set!"); 
    } 
    HttpClient httpclient = new DefaultHttpClient(); 
    HttpGet httpget = new HttpGet(serverURL + ":" + serverPort + "/maps"); 
    HttpResponse response = httpclient.execute(httpget); 
    HttpEntity entity = response.getEntity(); 
    if (entity != null) 
    { 
     InputStream instream = entity.getContent(); 
     int l; 
     byte[] tmp = new byte[2048]; 
     while ((l = instream.read(tmp)) != -1) 
     { 

     } 
    } 

有沒有什麼辦法來改變端口? 任何幫助,將不勝感激。

回答

0

我對HttpComponents有一點了解,但是我發現來自Apache站點的an example code,它可能對您有所幫助。你可以嘗試修改下面的代碼來解決你的問題。

 HttpHost target = new HttpHost("issues.apache.org", 443, "https"); 
     HttpGet request = new HttpGet("/"); 
     CloseableHttpResponse response = httpclient.execute(target, request); 
相關問題