0

This is my code:

String httpURL = "http://codespeed_server:8000/result/add/"; URL myurl = new URL(httpURL); HttpURLConnection con = (HttpURLConnection) myurl.openConnection(); con.setDoOutput(true); DataOutputStream output = new DataOutputStream(con.getOutputStream()); output.writeBytes(query); 

Can anybody tell me why this only works when I trail to it:

con.getResponseCode(); 

? The server only gets new entries when I call getResponseCode(). Is it a normal behavior ? Or is it a server-side issue ?

2
  • If you take out the con.getResponseCode(), what happens? Show what you do after writeBytes(). Commented Mar 8, 2013 at 16:01
  • Out of interest, does it get written if you call output.close() or output.flush() afterwards? Commented Mar 8, 2013 at 16:15

1 Answer 1

3

The URLConnection does not make a connection until one of the getResponse*, getInputStream methods (or other method which requires response data) is called (or connect()).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.