1

I have a FileNotFoundException in an URL, it seems that is the URL doesn't work on the HttpURLConnection because it runs in the browser. The Connection works on other URLs. The URL has a 200 status code so it has a normal code.

That's the AssyncTask code:

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);
    }
}`

`

  • This url requires that you must be logged in. So you must pass login details also. I got this message => Authorization Required This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required. – kishorepatel Jan 22 '16 at 17:08
  • check this => http://stackoverflow.com/questions/7019997/preemptive-basic-auth-with-httpurlconnection?rq=1 – kishorepatel Jan 22 '16 at 17:14

0 Answers0