代码: - try块不执行,如果我扩展Asynctask应用程序 崩溃,并且如果我不扩展Asynctask那么catch(Exception e)会给我一个错误消息 - “android.os.NetworkOnMainThradException”。try块不执行
尝试{
HttpURLConnection con = (HttpURLConnection) new URL("http://apis.hofficedemo1.ondemandcrm.co/AppRequestAPI").openConnection();
con.setRequestMethod("POST");
con.setDoInput(true);
con.setDoOutput(true);
con.connect();
con.getOutputStream().write(("txt_username=" + txt_username).getBytes());
con.getOutputStream().write(("txt_password=" + txt_password).getBytes());
con.getOutputStream().write(("appMode=" + appMode).getBytes());
con.getOutputStream().flush();
//System.out.println(txt_username+" "+txt_password+" "+appMode);
InputStream is = con.getInputStream();
byte[] b = new byte[1024];
while (is.read(b) != -1) {
System.out.println(Arrays.toString(b));
}
con.disconnect();
} catch (IOException e) {
Log.d("IOException", "Some error");
}
catch (Exception e){
e.printStackTrace();
}
请提catch块异常 写e.printStackTrace(),看看有没有什么异常,并张贴在这里 –
我不知道什么是与try块的问题。我试过各种方法,并明白这是有问题的HttpURLConnection –
添加e.printStackTrace()在catch块中看看有什么问题在尝试块 –