Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's the class that i use for http requests in java:</p> <pre><code>public class WSConnector { final String baseUrl = "http://www.myURL.com/"; //this is the base url of your services String realUrlWithParams=""; String realUrl=""; String params = ""; String charset = "UTF-8"; HttpURLConnection connection = null; public WSConnector(String serviceName,String params,String charset){ //we create the connector with everything we need (params must be ready as value pairs, serviceName is the name of your service): if (charset!=null){ this.charset = charset; } this.realUrlWithParams = baseUrl+serviceName+"?"+params; this.realUrl = baseUrl+serviceName; } public String getResponse(){//getResponse will get your the entire response String String result = ""; System.out.println("trying connection"); try { connection = (HttpURLConnection) new URL(realUrlWithParams).openConnection(); //connection.setRequestProperty("Accept-Charset", charset); int status = connection.getResponseCode(); System.out.println("status:"+status); if (status==HttpURLConnection.HTTP_OK){ InputStream responseStream = connection.getInputStream(); BufferedReader reader = null; reader = new BufferedReader(new InputStreamReader(responseStream)); for (String line; (line = reader.readLine()) != null;) { System.out.println("line is:" +line); result = result+line; System.out.println("result is:"+result); } } } catch (MalformedURLException e) { System.out.println("ERROR IN CONNECTOR"); e.printStackTrace(); } catch (IOException e) { System.out.println("ERROR IN CONNECTOR"); e.printStackTrace(); } System.out.println("finished connection"); return result; } </code></pre> <p>if wanting to know some more, visit this CW:</p> <p><a href="https://stackoverflow.com/questions/2793150/how-to-use-java-net-urlconnection-to-fire-and-handle-http-requests">httpurlconnection</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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