Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Http Post

 
Anand Shivadas
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic