2

I'm trying to upload a file to a server, but when I try to open the connection it fails and gives a FileNotFoundException, while the file is there. I my browser on my desktop it executes the php. This is my code:

  URL url = new URL("http://www.test.com/files/upload_file.php");
  connection = (HttpURLConnection) url.openConnection();

And this the error:

 12-07 14:43:01.337: W/System.err(19473): java.io.FileNotFoundException: http://www.test.com/files/upload_file.php
12-07 14:43:01.347: W/System.err(19473):    at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:177)
Diego
  • 4,011
  • 10
  • 50
  • 76

2 Answers2

2

I had your same problem and even if much time has gone since you made the question, this could be useful for the googlers.

Well, all I've done is adding this string:

connection.setDoOutput(false);

Also take a look at this

Community
  • 1
  • 1
Drilon Kurti
  • 402
  • 2
  • 18
0

I figured out in the end that the error came from and not from :

InputStream is = connection.getInputStream();

Changing into:

InputStream is = connection.getErrorStream();

fixed the error

Diego
  • 4,011
  • 10
  • 50
  • 76
  • hi, can you explain more detail about this..I have the same issue..so changing the code like above will solve this issue? – Mari_Yaguchi Mar 25 '14 at 07:19