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 8732089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:22:30+00:00 2026-06-13T09:22:30+00:00

Hey I try to send a HttpPost to an special Device in a local

  • 0

Hey I try to send a HttpPost to an special Device in a local network over wifi. If I try the same code on a simple Java application it will work, but If I try the same code on android I am not able to send the HttpPost.

String uri = "http://192.168.3.201:8080/remote/json-rpc/getPeripherals";
Log.i("uri", uri);
String requestBody = "{\"jsonrpc\":\"2.0\",\"method\":"
    + "\"configclient_homedevices/getPeripherals\",\"id\":"
    + "\"1349942076918\",\"params\":[]}";
Log.i("uri", uri);
String contentType = "application/json";
String userpassword = "foo:foo";
String encode = Base64.encodeToString(userpassword.getBytes(),
    Base64.URL_SAFE | Base64.DEFAULT);
try {
    URL url = null;
    url = new URL(uri);
    connection = (HttpURLConnection) url.openConnection(Proxy.NO_PROXY);
    connection.setDoOutput(true);
    connection.setRequestMethod("POST");
    connection.setRequestProperty("Authorization", "Basic" + encode);
    connection.setRequestProperty("Content-Type", contentType);
    connection.setRequestProperty("Accept", "application/json");
    connection.setRequestProperty("Content-Length",
        "" + Integer.toString(requestBody.getBytes().length));
    connection.setUseCaches(true);
    connection.setDoInput(true);
    DataOutputStream out = null;
    out = new DataOutputStream(connection.getOutputStream());
    out.write(requestBody.getBytes());
    out.flush();
    out.close();
} catch (IOException ioE) {
    connection.disconnect();
    ioE.printStackTrace();
}
// connection.connect();
try {
    if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
        Log.i("Status", toString().valueOf(connection.getResponseCode()));
        InputStream is = connection.getInputStream();
        BufferedReader rd = new BufferedReader(new InputStreamReader(is));
        String line;
        StringBuffer response = new StringBuffer();
        while ((line = rd.readLine()) != null) {
            response.append(line);
            response.append('\r');
        }
        rd.close();
        this.response = response.toString();
        Log.i("Response", response.toString());
    } else {
        Log.i("Status", toString().valueOf(connection.getResponseCode()));
        Log.i("Status-message", connection.getResponseMessage());
        connection.disconnect();
    }
} catch (IOException e) {
    e.printStackTrace();
}

this function is in a subclass which extends from AsyncTask. In the Manifest I enabled the Permission.INTERNET

<uses-permission android:name="android.permission.INTERNET" />

The result is:

10-23 14:52:51.590: W/System.err(5983): java.net.SocketException: No route to host
10-23 14:52:51.590: W/System.err(5983):     at org.apache.harmony.luni.platform.OSNetworkSystem.connect(Native Method)
10-23 14:52:51.590: W/System.err(5983):     at dalvik.system.BlockGuard$WrappedNetworkSystem.connect(BlockGuard.java:369)
10-23 14:52:51.590: W/System.err(5983):     at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:208)
10-23 14:52:51.590: W/System.err(5983):     at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:431)
10-23 14:52:51.590: W/System.err(5983):     at java.net.Socket.connect(Socket.java:901)
10-23 14:52:51.590: W/System.err(5983):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:75)
10-23 14:52:51.600: W/System.err(5983):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:48)
10-23 14:52:51.600: W/System.err(5983):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection$Address.connect(HttpConnection.java:304)
10-23 14:52:51.600: W/System.err(5983):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:89)
10-23 14:52:51.600: W/System.err(5983):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHttpConnection(HttpURLConnectionImpl.java:292)
10-23 14:52:51.600: W/System.err(5983):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.makeConnection(HttpURLConnectionImpl.java:250)
10-23 14:52:51.600: W/System.err(5983):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:217)
10-23 14:52:51.600: W/System.err(5983):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:624)
10-23 14:52:51.600: W/System.err(5983):     at com.febro.myfoo.fooLoginActivitiy$MakeConnection.doInBackground(fooLoginActivitiy.java:339)
10-23 14:52:51.610: W/System.err(5983):     at com.febro.myfoo.fooLoginActivitiy$MakeConnection.doInBackground(fooLoginActivitiy.java:1)
10-23 14:52:51.610: W/System.err(5983):     at android.os.AsyncTask$2.call(AsyncTask.java:252)
10-23 14:52:51.610: W/System.err(5983):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
10-23 14:52:51.610: W/System.err(5983):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
10-23 14:52:51.610: W/System.err(5983):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1081)
10-23 14:52:51.610: W/System.err(5983):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:574)
10-23 14:52:51.610: W/System.err(5983):     at java.lang.Thread.run(Thread.java:1020)
10-23 14:52:54.600: W/System.err(5983): java.net.SocketException: No route to host
10-23 14:52:54.600: W/System.err(5983):     at org.apache.harmony.luni.platform.OSNetworkSystem.connect(Native Method)
10-23 14:52:54.600: W/System.err(5983):     at dalvik.system.BlockGuard$WrappedNetworkSystem.connect(BlockGuard.java:369)
10-23 14:52:54.600: W/System.err(5983):     at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:208)
10-23 14:52:54.600: W/System.err(5983):     at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:431)
10-23 14:52:54.600: W/System.err(5983):     at java.net.Socket.connect(Socket.java:901)
10-23 14:52:54.600: W/System.err(5983):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:75)
10-23 14:52:54.600: W/System.err(5983):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:48)
10-23 14:52:54.600: W/System.err(5983):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection$Address.connect(HttpConnection.java:304)
10-23 14:52:54.600: W/System.err(5983):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:89)
10-23 14:52:54.600: W/System.err(5983):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHttpConnection(HttpURLConnectionImpl.java:292)
10-23 14:52:54.600: W/System.err(5983):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.makeConnection(HttpURLConnectionImpl.java:274)
10-23 14:52:54.600: W/System.err(5983):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.retrieveResponse(HttpURLConnectionImpl.java:1038)
10-23 14:52:54.600: W/System.err(5983):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:736)
10-23 14:52:54.600: W/System.err(5983):     at com.febro.myfoo.fooLoginActivitiy$MakeConnection.doInBackground(fooLoginActivitiy.java:351)
10-23 14:52:54.600: W/System.err(5983):     at com.febro.myfoo.fooLoginActivitiy$MakeConnection.doInBackground(fooLoginActivitiy.java:1)
10-23 14:52:54.600: W/System.err(5983):     at android.os.AsyncTask$2.call(AsyncTask.java:252)
10-23 14:52:54.600: W/System.err(5983):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
10-23 14:52:54.610: W/System.err(5983):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
10-23 14:52:54.610: W/System.err(5983):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1081)
10-23 14:52:54.610: W/System.err(5983):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:574)
10-23 14:52:54.610: W/System.err(5983):     at java.lang.Thread.run(Thread.java:1020)

The Exception is thrown at

out = new DataOutputStream(connection.getOutputStream());
  • 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-13T09:22:31+00:00Added an answer on June 13, 2026 at 9:22 am

    I found a solution for my Issue. The Issue was a fixed IP adress in the url after changing this I received a Status Code 400 Bad Request. This issue I got before I switched the request to a async task subclass. The solution for the Bad Request I found in the wireshark protocol. The Client send 2 Hypertext transfer protocols in one http Post. This caused by the android.Base64.encode() methode. The encoder inserted a /n after encoding the user:password string. In this case the client sent one http with only basic auth and a second with the rest the body without the basic auth. So the server could not read the request.

    To change this you should write android.Base64.encode(NO_WARP) this Flag will encode the username:password right.

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

Sidebar

Related Questions

Hey all. I'll try to make this brief and simple. :) I have 40
Hey guys I'm trying to write a simple socket program that basically send like
hey, Since a few weeks I'm try to program a PHP-Application with the smarty
Hey, I am using C# to try to send key commands to windows media
Hey, am writing an application to try out ideas and want to be able
Hey guys this is my html code: <div class=nakupy> <li class=icn_kategorie><a href=#>Nákupy</a> <div class=sub_menu>
hey guys having this really simple problem but cant seem to figure out have
hey i made a lot of search and found some similar types of code.
Hey all of you at Stackoverflow. I got this incredibly annoying problem. I try
Hey, i try to trim each string item of an list in groovy list.each()

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.