0

I am using java to connect to a website which has a form of type "multipart/form-data". It asks a user, pass, and file to upload.

When i run my java project, the response i get is "200". According to w3.org, anything in the 2xx class of HTTP responses indicates that "the client's request was successfully received, understood, and accepted."

My question is, if this is the response code i get, can i assume that the file was DEFINITELY uploaded to the site, and that there was no error? To put it in other wording, is the code "200" a guarantee that the file i sent is on the server, or is it just indicating that my POST request was understood?

Thank you!

Drifter64
  • 1,103
  • 3
  • 11
  • 30
  • It really depends on your Java HTTP server/services implementation. We don't know what it is doing after it receives the file. Perhaps it is deleting the file. Perhaps it is pushing the file to the file system, but it is then getting eaten by anti-virus. etc. – crush Jan 27 '14 at 15:26
  • no. I am connecting to the website in order to automatically upload a file. My java program is the client, not the server. – Drifter64 Jan 27 '14 at 15:26
  • I see what you are saying. The wording is weird, but probably acceptable. I'd probably call that an HTTP or Web application rather than a website. – crush Jan 27 '14 at 15:28

1 Answers1

2

The HTTP status code 200 states that

The request has succeeded.

The server is therefore telling you that the request you made was successful. However, this doesn't tell you anything about what the web application did. It's up to the web application itself to tell you, possibly as part of the HTTP response.

You should check the web application API or specification and interpret the HTTP response accordingly.

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
  • Would any useful info be given, besides "200 OK." if i did this: ((HttpURLConnection) connection).getResponseMessage() ? The documentation for this method in my IDE is ambiguous about this. In other words, how would i get the full response, or maybe even the code for the page that i would see if i was manually filling out the form? The site DOES kick out error codes for things like wrong user/pass or wrong file type. – Drifter64 Jan 27 '14 at 15:29
  • @Drifter64 Again, it depends on the implementation. You haven't provided us any information about the HTTP server side. – crush Jan 27 '14 at 15:32
  • @Drifter64 No, that method just gives the reason phrase. So for `200 OK`, it would give you `OK`. – Sotirios Delimanolis Jan 27 '14 at 15:33
  • @Drifter64 Status codes are HTTP server/client specific. Your web application does application specific things. – Sotirios Delimanolis Jan 27 '14 at 15:34
  • @crush, i did update my comment moments before you commented. The server side is somewhat unknown to me as it belongs to someone else. What i know is what ive just given, which is that the page will direct me to another URL with error codes if i manually upload from a browser. I'm wanting to get this page data somehow with my URLConnection/HttpURLConnection object. – Drifter64 Jan 27 '14 at 15:35
  • Here is the relevant RFC section for the [Response](http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html) – crush Jan 27 '14 at 15:35
  • @Drifter64 It's likely that they are using some type of generic HTTP request handler which probably outputs `OK` as Sotirios has said. The server has the ability to send back a custom status phrase. If they do or not depends on their implementation, unfortunately. Could you contact the server operator, and ask them if there is anyway you can be 100% sure the file was uploaded? – crush Jan 27 '14 at 15:37
  • I have found the information i need. Thank you all for your help! – Drifter64 Jan 27 '14 at 15:52