wood burning stoves 2.0*
The moose likes Java in General and the fly likes Http Post Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Http Post" Watch "Http Post" New topic
Author

Http Post

Anand Shivadas
Greenhorn

Joined: Oct 17, 2000
Posts: 22
Hi all,
I'm creating a HttpURLConnection, and opening connection with some url, here is the code
HttpURLConnection con;
URL url = new URL(getUrlPath());
URLConnection ucon = (URLConnection) url.openConnection();
if (ucon instanceof HttpURLConnection) {
con = (HttpURLConnection)ucon;
After opening connection I would be writing to that url by reading from a file, after that I would be retriving status code from con object
int responseCode = con.getResponseCode()
It works fine if we post a file with data, but if we try to post empty file (no data at all), it gives file not found exception while retriving response code. The File not found exception is with URL. My initial thought is, because we are not posting any data to server, there is only logical connection between client and server until we post some data to server. In normal case when we post file with data, it actually contacting server and we can expect response code for that, where as with out posting any data we are trying to get the status code that's why its giving error b'cos still it's logical connection, i.e with out posting data we are expecting response code from server.
Anybody has idea how we can get rid of this exception while posting empty file?
any help would be much appriciated.
Thanks,
Anand
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Http Post
 
Similar Threads
Java Website post
How to get the HTTP Response code when a user has provided a invalid url.
Communication between Servlet and Applet
Applet Servlet communication with struts?
Problems connecting to LDAP from Weblogic Server: BAD_CERTIFICATE error!