Address family not supported by protocol exception

I am trying to send a pair of values ​​from an Android application to the web service that I installed. I use Http Post to send, but when I start the application, I get an error message with the request. Java.net.SocketException: The address family is not supported by the protocol.

I get this when debugging with both an emulator and a device connected to Wi-Fi. I have already added permission to the Internet using:

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

This is the code I use to send 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();
    }

I also know that my web service is working fine, because when I submit 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 saw questions about similar problems, but I really did not find a solution.

thank

+3
source share
5 answers

AndroidManifest.xml:

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

:

 catch(SocketException ex)
       {
         Log.e("Error : " , "Error on soapPrimitiveData() " + ex.getMessage());
           ex.printStackTrace();
       }
+1

. , , . , ip/port. , , .

0

ip 192.168.0.12:8000 10.0.2.2:8000. Tht

0

, , IP-. , , ufw, IP- .

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

AndroidManifest.xml.

0

Source: https://habr.com/ru/post/1793356/


All Articles