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

  • SEARCH
  • Home
  • 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 8240707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:34:57+00:00 2026-06-07T20:34:57+00:00

I need the condition of setting no proxy in my application; for that I

  • 0

I need the condition of setting no proxy in my application; for that I used the following code:

URL url = null;

try {
    url = new URL(uri.toURL().toString());
} catch (MalformedURLException e3) {
    e3.printStackTrace();
}

try {
    //client = (HttpURLConnection) url.openConnection(java.net.Proxy.NO_PROXY);
    Properties systemProperties = System.getProperties();

    systemProperties.setProperty("http.nonProxyHosts",ServerIP);
    systemProperties.setProperty( "proxySet", "false" );
    systemProperties.setProperty("http.proxyHost","");
    systemProperties.setProperty("http.proxyPort","");
    URLConnection conn = url.openConnection(Proxy.NO_PROXY);


    conn.connect();
} catch (IOException e3) {
    e3.printStackTrace();
}

But I got network unreachable exception!!

Any help!!

  • 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-07T20:34:58+00:00Added an answer on June 7, 2026 at 8:34 pm

    If I do not misunderstand your question… You want to connect to server directly when it is connecting via WIFI ?

    HttpURLConnection con =null;
    URL url = new URL("xxxxx");
    boolean isProxy=true;
    
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if(cm!=null){
        NetworkInfo  ni = cm.getActiveNetworkInfo();
        if(ni!=null){
            if(! ni.getTypeName().equals("WIFI")){
               isProxy=false;
            }
            if(isProxy){
                Proxy proxy=new Proxy(java.net.Proxy.Type.HTTP,new InetSocketAddress(android.net.Proxy.getDefaultHost(),android.net.Proxy.getDefaultPort()));
                con = (HttpURLConnection) url.openConnection(proxy);
            }else{
                con = (HttpURLConnection) url.openConnection();
            }
        }
    }
    

    p.s. Please note that the code snippet above may miss some error handling. Thanks 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to do a url rewrite maintaining following condition: rewrite http://domain.net (or http://www.domain.net
I need to select a node if a condition is matched. I'm totally new
I need to add a new SELECT statement whose search condition include something like
Rails: I need to set a condition in a has_many that needs the self.id
in my application I need to store settings that are 'global' (i.e. not user
I have this following code fragment which is accessed by different threads. try {
I need to check for a condition on each page I visit on the
I need to value an if condition, but I need to be careful about
I need to check for an condition and if it is satisfied i need
I need to be able to strip out a condition in a string, here

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.