我正在尝试从安卓应用向我设置的网络服务发送一些值。我使用 Http Post 进行发送,但当我运行应用程序时,我收到了错误消息-请求时间失败 java.net.SocketException: 协议不支持的地址族。
在使用模拟器和通过 wifi 连接的设备进行调试时,我都遇到了这个问题。我已经使用以下代码添加了互联网权限:
这是我使用的代码发送数值。
我知道我的网络服务运行良好,因为当我从HTML页面发送值时,它可以正常工作。
在使用模拟器和通过 wifi 连接的设备进行调试时,我都遇到了这个问题。我已经使用以下代码添加了互联网权限:
<uses-permission android:name="android.permission.INTERNET" />
这是我使用的代码发送数值。
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();
}
我知道我的网络服务运行良好,因为当我从HTML页面发送值时,它可以正常工作。
<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"/>
我看到了类似问题的提问,但并没有真正找到解决方案。
谢谢。