Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8316065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:16:24+00:00 2026-06-08T21:16:24+00:00

URL url = new URL(URL path); HttpURLConnection connection = (HttpURLConnection)url.openConnection(); connection.setConnectTimeout(30000); connection.setReadTimeout(30000); connection.setDoInput(true); connection.setUseCaches(true);

  • 0
                URL url = new URL(URL path);
                HttpURLConnection connection = (HttpURLConnection)url.openConnection();
                connection.setConnectTimeout(30000);
                connection.setReadTimeout(30000);
                connection.setDoInput(true);
                connection.setUseCaches(true);
                connection.connect();
                InputStream is = connection.getInputStream();

Above code is my code of Android.
I try to connect an URL path and get information to InputStream is.
I try to connect the same URL path with the same wifi by Android phone and iPhone.
Android phone spend about 10 seconds by moto phones or HTC phones.
But iPhone only spend less than 3 seconds.
I think it may not only cause by wifi speed.(Because I try with the same wifi).
So I want to ask that is it possible improved by code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T21:16:25+00:00Added an answer on June 8, 2026 at 9:16 pm

    Try using the apache HttpClient instead of URL.openConnection()

    DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpGet get = new HttpGet("http://your.url");
    
    HttpResponse response;
    try {
        response = httpClient.execute(get);
        InputStream is = response.getEntity().getContent();
    } catch(Exception e){
        e.printStackTrace();
    }
    

    Edit:

    In API level 22 (Android M) the Apache HttpClient will be removed, so this approach is deprecated.

    For more infor see :
    http://developer.android.com/preview/behavior-changes.html#behavior-apache-http-client

    The recommended approach is to use HttpUrlConnection (http://developer.android.com/reference/java/net/HttpURLConnection.html):

    URL url = new URL("http://your.url");
    HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
    try {
        InputStream in = new BufferedInputStream(urlConnection.getInputStream());
        readStream(in);
    } finally {
        urlConnection.disconnect();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

URL url = new URL(http://www.example.com/comment); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true); connection.setRequestMethod(POST); Is connection.setRequestProperty(key,
URL url = new URL(http://twitter.com/statuses/update.xml); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setDoOutput(true); String cridentials =
URL url = new URL(http://download.thinkbroadband.com/20MB.zip); URLConnection connection = url.openConnection(); File fileThatExists = new File(path);
Below code : URL oracle = new URL(http://www.oracle.com/); URLConnection inputStream =oracle.openConnection(); InputStream in =
I want users#new and tasks#index to display as the root path URL, i.e. /
URL url = new URL(http://localhost:8080/Work/images/abt.jpg); InputStream in = new BufferedInputStream(url.openStream()); ByteArrayOutputStream out = new
URL oauth = new URL(URL); URLConnection oauth_connection = oauth.openConnection(); BufferedReader in = new BufferedReader(new
How can I create in real-time a new URL path in Ruby on Rails?
An example: getAppletContext().showDocument( new URL(javascript:alert(document.getElementById('textbox').value); )); Instead of alerting this textbox value, I want
I'm trying to define a new URL handler under OSX that will point at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.