Note that there are some explanatory texts on larger screens.

plurals
  1. POsending data to server with httpUrlConnection
    text
    copied!<p>I am trying to create a Simplest WebServer and Client using HTTP. I should use a tunnel way that uses two connections at the same time; one is a GET connection to recieve data and the other is a POST connection to send data back.</p> <p>Below is my code:</p> <pre><code>//client GET Request setoURL(new URL("http://" + input.getIp() + ":" + input.getPort() + input.getUrlPath())); conn = (HttpURLConnection) getoURL().openConnection(); conn.setRequestMethod("GET"); conn.setReadTimeout(5000); conn.addRequestProperty("User-Agent", "VVTK (ver=40)"); conn.addRequestProperty("Accept", "application/x-vvtk-tunnelled"); conn.addRequestProperty("x-sessioncookie", uniqueId()); conn.addRequestProperty("Pragma", "no-cache"); conn.addRequestProperty("Cache-Control", "no-cache"); conn.setRequestProperty("Authorization",/*The Authorization*/); conn.getResponseCode(); //Client POST request HttpURLConnection second2 = (HttpURLConnection) apiCommand.getoURL().openConnection(); second2.setRequestMethod("POST"); second2.setReadTimeout(5000); second2.setRequestProperty("User-Agent", "VVTK (ver=40)"); second2.setRequestProperty("x-sessioncookie", xsession); second2.setRequestProperty("Pragma", "no-cache"); second2.setRequestProperty("Cache-Control", "no-cache"); second2.setRequestProperty("Content-Length", "7"); second2.setRequestProperty("Expires", "Sun, 9 Jan 1972 00:00:00 GMT"); second2.setRequestProperty("VerifyPassProxy", "yes"); second2.setRequestProperty("Authorization", /*The Authorization*/); second2.setDoOutput(true); reqStream = new DataOutputStream(second2.getOutputStream()); reqStream.writeBytes("Q2FuU2Vl"); reqStream.flush(); in = new BufferedReader(new InputStreamReader(second.getInputStream())); String inputLine = ""; while ((inputLine = in.readLine()) != null) { System.out.println(inputLine); } </code></pre> <p>The problem is the post request not sent. The first connection ((GET Request)) will send me the events or all responses. I should never disconnect or get data from the second connection (POST request).</p> <h3>Question</h3> <p>Why is the POST request not send?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload