Note that there are some explanatory texts on larger screens.

plurals
  1. PO404 Error when sending HTTP request through java
    text
    copied!<p>I seem to be getting a 404 error when sending a http post to a sinatra server. I am trying to make the server page the text I send to it, here's my code I think it may be something wrong with my server but I'm not sure:</p> <pre><code>private void sendInfo() throws Exception { //make the string and URL String url = "http://localhost"; URL obj = new URL(url); HttpsURLConnection con = (HttpsURLConnection) obj.openConnection(); //add request header con.setRequestMethod("POST"); con.setRequestProperty("User-Agent", USER_AGENT); con.setRequestProperty("Accept-Language", "en-US,en;q=0.5"); String urlParameters = "sn=C02G8416DRJM&amp;cn=&amp;locale=&amp;caller=&amp;num=12345"; //send post con.setDoOutput(true); DataOutputStream wr = new DataOutputStream(con.getOutputStream()); wr.writeBytes(urlParameters); wr.flush(); wr.close(); int responseCode = con.getResponseCode(); System.out.println("\nSending 'post' request to url: " + url); System.out.println("Post parameters : " + urlParameters); System.out.println("Response code: " + responseCode); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer response = new StringBuffer(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); //print result System.out.println(response.toString()); } </code></pre> <p>and here is the sinatra server (ruby):</p> <pre><code>require 'sinatra' get '/' do 'hello mate' end get '/boo' do 'trololo' end </code></pre>
 

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