我在URL中有一个FileNotFoundException,似乎这个URL在HttpURLConnection上不起作用,因为它在浏览器中运行。 Connection适用于其他URL。 该URL具有200状态代码,因此它具有正常代码。
那是AssyncTask代码:
private class CrearRegistroTask extends AsyncTask<String, Void, String> {
/*
EJEMPLO DE LA CREACIÓN DE UN REGISTRO
*/
@Override
protected String doInBackground(String... params) {
InputStream iS = null;
String data="";
try {
URL url = new URL("http://user:pass@denunciaty.florida.com.mialias.net/api/reporte/nuevo/Prueba3/Descripcion3/1/Ejempo/2/5/senyal");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setReadTimeout(10000);
con.setConnectTimeout(15000);
con.setRequestMethod("GET");
con.setDoInput(true);
con.connect();
iS = new BufferedInputStream(con.getInputStream());
con.getResponseCode();
if (iS != null) {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(iS));
String line = "";
while ((line = bufferedReader.readLine()) != null)
data += line;
}
iS.close();
return data;
} catch (IOException e) {
e.printStackTrace();
} finally {
if(iS !=null){
try {
iS.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return data;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
tv.setText(s);
}
}`
`