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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:44:21+00:00 2026-05-15T11:44:21+00:00

I’ve been banging my head trying to figure out how to send a post

  • 0

I’ve been banging my head trying to figure out how to send a post method in Android. This is how my code look like:

public class HomeActivity extends Activity implements OnClickListener {

    private TextView textView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        textView = (TextView) findViewById(R.id.text);
        Button button = (Button)findViewById(R.id.button);
        button.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {    
        HttpPost httpMethod = new HttpPost("http://www.example.com/");
        httpMethod.addHeader("Accept", "text/html");
        httpMethod.addHeader("Content-Type", "application/xml");


        AndroidHttpClient client = AndroidHttpClient.newInstance("Android");
        String result = null;
        try {
            HttpResponse response = client.execute(httpMethod);
            textView.setText(response.toString());

            HttpEntity entity = response.getEntity();

            Log.i(HomeActivity.class.toString(), result);
            textView.setText("Invoked webservice");
        } catch (IOException e) {
            e.printStackTrace();
            Log.e(HomeActivity.class.toString(), e.getMessage());
            textView.setText("Something wrong:" + e.getMessage());
        }
    }
}

This is the exception that I get:

I/ARMAssembler(   59): generated scanline__00000177:03515104_00001001_00000000 [
 91 ipp] (114 ins) at [0x334348:0x334510] in 1430659 ns
W/System.err(  272): java.net.UnknownHostException: www.example.com
W/System.err(  272):    at java.net.InetAddress.lookupHostByName(InetAddress.jav
a:513)
W/System.err(  272):    at java.net.InetAddress.getAllByNameImpl(InetAddress.jav
a:278)
W/System.err(  272):    at java.net.InetAddress.getAllByName(InetAddress.java:24
2)
W/System.err(  272):    at org.apache.http.impl.conn.DefaultClientConnectionOper
ator.openConnection(DefaultClientConnectionOperator.java:136)
W/System.err(  272):    at org.apache.http.impl.conn.AbstractPoolEntry.open(Abst
ractPoolEntry.java:164)
W/System.err(  272):    at org.apache.http.impl.conn.AbstractPooledConnAdapter.o
pen(AbstractPooledConnAdapter.java:119)
W/System.err(  272):    at org.apache.http.impl.client.DefaultRequestDirector.ex
ecute(DefaultRequestDirector.java:348)
W/System.err(  272):    at org.apache.http.impl.client.AbstractHttpClient.execut
e(AbstractHttpClient.java:555)
W/System.err(  272):    at org.apache.http.impl.client.AbstractHttpClient.execut
e(AbstractHttpClient.java:487)
W/System.err(  272):    at org.apache.http.impl.client.AbstractHttpClient.execut
e(AbstractHttpClient.java:465)
W/System.err(  272):    at android.net.http.AndroidHttpClient.execute(AndroidHtt
pClient.java:243)
W/System.err(  272):    at com.collaboapp.android.HomeActivity.onClick(HomeActiv
ity.java:152)
W/System.err(  272):    at android.view.View.performClick(View.java:2408)
W/System.err(  272):    at android.view.View$PerformClick.run(View.java:8816)
W/System.err(  272):    at android.os.Handler.handleCallback(Handler.java:587)
W/System.err(  272):    at android.os.Handler.dispatchMessage(Handler.java:92)
W/System.err(  272):    at android.os.Looper.loop(Looper.java:123)
W/System.err(  272):    at android.app.ActivityThread.main(ActivityThread.java:4
627)
W/System.err(  272):    at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err(  272):    at java.lang.reflect.Method.invoke(Method.java:521)
W/System.err(  272):    at com.android.internal.os.ZygoteInit$MethodAndArgsCalle
r.run(ZygoteInit.java:868)
W/System.err(  272):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.ja
va:626)
W/System.err(  272):    at dalvik.system.NativeStart.main(Native Method)
E/class android.HomeActivity(  272): www.example.com
D/ThrottleService(   59): finally have imsi - retreiving data
D/ThrottleService(   59): onPollAlarm - roaming =false, read =0, written =0, new
 total =0
D/SntpClient(   59): request time failed: java.net.SocketException: Address fami
ly not supported by protocol

What am I doing wrong here? Is there anything that I may need to configure from the Android emulator to get this working?

Thank you for your 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-05-15T11:44:22+00:00Added an answer on May 15, 2026 at 11:44 am

    it seems that AndroidHttpClient is responsible for that exception. Your example will work

    • if use set the ‘INTERNET’ persmission as suggested
    • replace ‘AndroidHttpClient’ with ‘DefaultHttpClient’
    • remove the line ‘Log.i(HomeActivity.class.toString(), result);’ because result is null

    It is not clear to me why this class does not work as excpected, maybe somebody could explain. This thread discussed the problem too but there is also no explaination why the code fails: http://groups.google.de/group/android-developers/browse_thread/thread/cc59efb9475ac557/81116369f2c6bd7a?hl=de&lnk=gst&q=This+thread+forbids+HTTP+requests#81116369f2c6bd7a.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a jquery bug and I've been looking for hours now, I can't
I'm looking for suggestions for debugging... If you view this site in Firefox or
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.