首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >HttpComponents -连接到不同的端口

HttpComponents -连接到不同的端口
EN

Stack Overflow用户
提问于 2011-11-14 02:35:07
回答 1查看 129关注 0票数 1

我必须编写一个android客户端,在其中我应该使用HttpComponents连接到8080端口上的特定服务器。到目前为止,我找到的只是Apache站点上的Examplecode,除了它连接的Port之外,它几乎完全符合我的需要:

代码语言:javascript
复制
    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)
        {

        }
    }

有什么方法可以改变端口吗?任何帮助都将不胜感激。

EN

回答 1

Stack Overflow用户

发布于 2013-12-19 21:41:46

我对HttpComponents略知一二,但我从Apache-site找到了an example code,这可能会对你有所帮助。您可以尝试像下面这样针对您的问题修改代码。

代码语言:javascript
复制
        HttpHost target = new HttpHost("issues.apache.org", 443, "https");
        HttpGet request = new HttpGet("/");
        CloseableHttpResponse response = httpclient.execute(target, request);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8113723

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档