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)
4
  • 1
    Have you tried another url (google for ex.)? Commented Dec 7, 2013 at 23:04
  • Is this php file a local file or one hosted on a remote server? Commented Dec 7, 2013 at 23:06
  • It's on a remote server. But I get a different error when I use google. So there might be something going on with my server. Thanks Commented Dec 7, 2013 at 23:08
  • It is strange, I'm able to connect through my browser on the phone, but not like above. Commented Dec 7, 2013 at 23:16

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

hi, can you explain more detail about this..I have the same issue..so changing the code like above will solve this issue?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.