Asked
Modified
10 years, 3 months ago
Viewed
3k times
Part
of PHP and Mobile Development Collectives
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)
asked Dec 7, 2013 at 22:58
Diego
4,14911 gold badges53 silver badges76 bronze badges
-
1Have you tried another url (google for ex.)?MeNa– MeNa2013年12月07日 23:04:16 +00:00Commented Dec 7, 2013 at 23:04
-
Is this php file a local file or one hosted on a remote server?kabuto178– kabuto1782013年12月07日 23:06:05 +00:00Commented 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. ThanksDiego– Diego2013年12月07日 23:08:20 +00:00Commented Dec 7, 2013 at 23:08
-
It is strange, I'm able to connect through my browser on the phone, but not like above.Diego– Diego2013年12月07日 23:16:15 +00:00Commented Dec 7, 2013 at 23:16
2 Answers 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
answered Sep 18, 2015 at 17:25
Drilon Kurti
3992 silver badges18 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
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
answered Dec 8, 2013 at 22:31
Diego
4,14911 gold badges53 silver badges76 bronze badges
1 Comment
Mari_Yaguchi
hi, can you explain more detail about this..I have the same issue..so changing the code like above will solve this issue?
lang-php