Address family not supported by protocol exception

Posted by srg on Stack Overflow See other posts from Stack Overflow or by srg
Published on 2011-02-20T08:49:29Z Indexed on 2012/11/07 11:01 UTC
Read the original article Hit count: 243

Filed under:
|

I'm trying to send a couple of values from an android application to a web service which I've setup. I'm using Http Post to send them but when I run the application I get the error- request time failed java.net.SocketException: Address family not supported by protocol.

I get this while debugging with both the emulator as well as a device connected by wifi. I've already added the internet permission using:

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

This is the code i'm using to send the values

    void insertData(String name, String number) throws Exception {
    String url = "http://192.168.0.12:8000/testapp/default/call/run/insertdbdata/";
    HttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost(url);

    try {
        List<NameValuePair> params = new ArrayList<NameValuePair>(2);

        params.add(new BasicNameValuePair("a", name));

        params.add(new BasicNameValuePair("b", number));
        post.setEntity(new UrlEncodedFormEntity(params));
        HttpResponse response = client.execute(post);
    }catch(Exception e){
        e.printStackTrace();
    }

Also I know that my web service work fine because when I send the values from an html page it works fine -

<form name="form1" action="http://192.168.0.12:8000/testapp/default/call/run/insertdbdata/" method="post">
    <input type="text" name="a"/>
    <input type="text" name="b"/>
    <input type="submit"/>

I've seen questions of similar problems but haven't really found a solution.

Thanks

© Stack Overflow or respective owner

Related posts about java

Related posts about android