aspose file tools
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

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Http Post" Watch "Http Post" New topic

Http Post

Anand Shivadas

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.
Have you tried LearnNowOnline?
subject: Http Post