Ik ben de API van telenet eens aan het uittesten en ik wou een HTTP POST request sturen in java. Nu ik doe dit op deze manier:
Code: Selecteer alles
   try {
            String xmldata = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                    "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns1=\"http://www.telenet.be/TelemeterService/\">\n" +
                    "  <SOAP-ENV:Body>\n" +
                    "    <ns1:RetrieveUsageRequest>\n" +
                    "      <UserId>test</UserId>\n" +
                    "      <Password>test</Password>\n" +
                    "    </ns1:RetrieveUsageRequest>\n" +
                    "  </SOAP-ENV:Body>\n" +
                    "</SOAP-ENV:Envelope>";
            URL myurl = new URL("https://t4t.services.telenet.be/TelemeterService");
            HttpsURLConnection con = (HttpsURLConnection) myurl.openConnection();
            con.setRequestMethod("POST");
            con.setRequestProperty("Content-length", String.valueOf(xmldata.length()));
            con.setRequestProperty("Content-Type", "text/xml; charset=\\\"utf-8\\\"\\r\\n");
            con.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36");
            con.setDoOutput(true);
            con.setDoInput(true);
            DataOutputStream output = new DataOutputStream(con.getOutputStream());
            output.writeBytes(xmldata);
            output.close();
            DataInputStream input = new DataInputStream(con.getInputStream());
            for (int c = input.read(); c != -1; c = input.read())
                System.out.print((char) c);
            input.close();
            System.out.println("Resp Code:" + con.getResponseCode());
            System.out.println("Resp Message:" + con.getResponseMessage());
        }
        catch (IOException se)
        {
            se.printStackTrace();
        }Code: Selecteer alles
java.io.IOException: Server returned HTTP response code: 500 for URL: https://t4t.services.telenet.be/TelemeterService
	at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1459)
	at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:234)
	at be.telenet.telemeterservice.Main.main(Main.java:42)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134) 
					 
  
 




