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
source
share