本文介绍了HttpComponents - 连接到不同的端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须编写一个Android客户端,其中我应该使用HttpComponents连接到端口8080上的特定服务器。
现在,我发现的只是来自Apache网站的Examplecode,对于我需要的东西几乎是完美的,除了它连接的端口:

I have to write an android client, in which i should use HttpComponents to connect to a specific Server on Port 8080.For now, all i've found, was the Examplecode from the Apache-site, which is nearly perfect for what i need, except the Port it connects to:

    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)
        {

        }
    }

有没有办法改变港口?
任何帮助都将不胜感激。

Is there any way to change the Port?Any help would be appreciated.

推荐答案

我对HttpComponents了解一点,但我发现网站,这可能会帮助你。你可以尝试修改下面的代码来解决你的问题。

I know a little about HttpComponents, but I find an example code from Apache-site, which may help you. You can try to modify the code like below for your problem.

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

这篇关于HttpComponents - 连接到不同的端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 21:21