Quantcast
Viewing all articles
Browse latest Browse all 3285

HTTP request to HANA Cloud Platform

Hello!

I'm trying the IoT Sof the SAP HANA Cloud Platform.

I want to post a http request to the HANA Cloud Platform. At first i tried that example with Python and it worked. Now I want to do this with Java but it doesn't work. This program does not send anything.

The message, URL and authorization token are correct.

 

Here is my code but what doesn't work with that?

 

 

 

    String body =  "{\"mode\":\"sync\",\"messageType\":\"f0b6a457489141cfcbd4\",\"messages\":[{\"Hoehe\":300.49,\"Geblaesespannung\":20.78,\"Temperatur\":79.8,\"Betriebssekunden\":1.6,\"SollHoehe\":299.45}]}";

   

   try{  
  
   URL url = new URL("https://iotmmsp1xxxxxxxxtrial.hanatrial.ondemand.com/com.sap.iotservices.mms/v1/api/http/data/f59c1da5-c7a7-491e-9bdf-b03f5e0e769");
   HttpURLConnection connection = (HttpURLConnection) url.openConnection();
   connection.setRequestMethod("POST");
   connection.setDoInput( true );
   connection.setDoOutput( true );
   connection.setUseCaches( false );
   connection.setRequestProperty( "Content-Type","application/json");
   connection.setRequestProperty( "Content-Length", String.valueOf(body.length()) );
   connection.setRequestProperty("Authorization", "Bearer 633e79f191e4ac51fee9de3a7e7c4ff5");

 

   OutputStreamWriter writer = new OutputStreamWriter( connection.getOutputStream() );
   writer.write(body);
   writer.flush();

 

 

   BufferedReader reader = new BufferedReader(
                          new InputStreamReader(connection.getInputStream()) );

 

   for ( String line; (line = reader.readLine()) != null; )
   {
      System.out.println( line );
   }

 

   writer.close();
   reader.close();
   }catch (Exception ex){
   System.out.println(ex.toString());
   }

Viewing all articles
Browse latest Browse all 3285

Trending Articles