0
当我运行我的android应用程序时,出现以下异常: 我正在进入asynctask,但记录此异常。Android:AsyncTask中的Java Net Socket异常
03-15 16:49:21.456 16854-16892/com.ashwinbhy.phpwrite W/Ashwin﹕ java.net.SocketException: socket failed: EACCES (Permission denied)
我已经包括了我的manifest.xml这里面的权限:
<uses-permission android:name="android.permission.internet"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.access_network_state"/>
的代码是:
try {
URL url = new URL("http://10.0.0.2/tt.php");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(10000);
conn.setConnectTimeout(15000);
conn.setRequestMethod("POST");
conn.setDoInput(true);
conn.setDoOutput(true);
Uri.Builder builder = new Uri.Builder()
.appendQueryParameter("bus_id", busid)
.appendQueryParameter("lat", lat)
.appendQueryParameter("lon", lon);
String query = builder.build().getEncodedQuery();
OutputStream os = conn.getOutputStream();
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(os, "UTF-8"));
writer.write(query);
writer.flush();
writer.close();
os.close();
conn.connect();
}
catch(Exception e){
Log.w("Ashwin",e.toString()+"inside the exception log");
return "error";
}
可有人请点我要去哪里错了?
我addding日志:
03-15 17:15:42.140 9003-9034/com.ashwinbhy.phpwrite I/System.out﹕ open:http://10.0.0.2/tt.php
03-15 17:15:42.141 9003-9034/com.ashwinbhy.phpwrite D/libc-netbsd﹕ [getaddrinfo]: hostname=10.0.0.2; servname=(null); cache_mode=(null), netid=0; mark=0
03-15 17:15:42.141 9003-9034/com.ashwinbhy.phpwrite D/libc-netbsd﹕ [getaddrinfo]: ai_addrlen=0; ai_canonname=(null); ai_flags=4; ai_family=0
03-15 17:15:42.142 9003-9034/com.ashwinbhy.phpwrite I/System.out﹕ [CDS][DNS] getAllByNameImpl netId = 0
03-15 17:15:42.142 9003-9034/com.ashwinbhy.phpwrite D/libc-netbsd﹕ [getaddrinfo]: hostname=10.0.0.2; servname=(null); cache_mode=(null), netid=0; mark=0
03-15 17:15:42.142 9003-9034/com.ashwinbhy.phpwrite D/libc-netbsd﹕ [getaddrinfo]: ai_addrlen=0; ai_canonname=(null); ai_flags=4; ai_family=0
03-15 17:15:42.143 9003-9034/com.ashwinbhy.phpwrite I/System.out﹕ [CDS]rx timeout:10000
03-15 17:15:42.143 9003-9034/com.ashwinbhy.phpwrite I/System.out﹕ [socket][3] connection /10.0.0.2:80;LocalPort=55951(15000)
03-15 17:15:42.143 9003-9034/com.ashwinbhy.phpwrite I/System.out﹕ [CDS]connect[/10.0.0.2:80] tm:15
谢谢。 我没有得到例外,但我的页面仍然无法访问。 我没有收到任何错误。 – ashwinbhy
@ashwinbhy检查更新。 –
我在本地网络上运行它10.0.0.2/tt.php从我的浏览器工作正常 – ashwinbhy