app调试的问题
手机向服务器发送post请求
URL url =new URL(Path);
HttpURLConnection urlConnection = (HttpURLConnection) url
.openConnection();
urlConnection.setConnectTimeout(3000);
urlConnection.setRequestMethod("POST");
urlConnection.setDoInput(true);// 表示从服务器获取数据
urlConnection.setDoOutput(true);// 表示向服务器写数据\
byte[] mydata = requestString.getBytes();
OutputStream outputStream=null;
try {
outputStream = (OutputStream) urlConnection.getOutputStream();
} catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
outputStream.write(mydata,0,mydata.length);
outputStream.close();
int responseCode = urlConnection.getResponseCode();
if (responseCode == 200) {
returnString = changeInputStream(urlConnection.getInputStream(), "utf-8");
return returnString;
}
手机是是通过wifi连接服务器的,总是报错transport endpoint is not connected
我把http的请求直接复制在浏览器地址栏里,直接访问,是正常的
比如我在浏览器里直接输入 http://10.0.0.14:8080/Huning/servlet/Login?username=&password=
服务器能正常收到
手机的话就不行
在配置文件里,也已经配置了网络权限
<!-- 使用网络功能所需权限 -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" >
</uses-permission>
</uses-permission>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" >
</uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" >
</uses-permission>
有又遇到过这个问题的朋友吗,怎么解决的?
[解决办法]
Http请求要在子线程中进行