Jump to content


Sending data stream to carriots from java

HTTP response 302

  • Please log in to reply
1 reply to this topic

#1 tonygeorge



  • Members
  • Pip
  • 1 posts

Posted 13 November 2016 - 11:55 AM


for test purposes I'am trying to send a data stream to carriots from a java program. The problem: my java client becomes a "found 302" message. the message tells that the request has been redirected to carriots main page.

The message (HTML) is:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"><html><head><title>302 Found</title></head><body><h1>Found</h1><p>The document has moved <a href="https://www.carriots.com/">here</a>.</p><hr><address>Apache/2.2.22 (Ubuntu) Server at www.carriots.com Port 80</address></body></html>


my java code is very direct:


  String url = "http://www.carriots.com:80";
  String APIKEY = "here my api key";  
  String DEVICE = "defaultDevice@myaccount.myaccount";
  URL obj = new URL(url);
  HttpURLConnection con = (HttpURLConnection) obj.openConnection();
  System.out.println("Connection ok..");
  String json = "{\"protocol\":\"v2\",\"device\":\""+DEVICE+"\",\"at\":\"now\",\"data\":{\"weight\":\"ON\"}}";
  //add reuqest header
  con.setRequestProperty("Host", "api.carriots.com");
  con.setRequestProperty("Accept", "application/json");
  con.setRequestProperty("User­Agent","defaultDevice@myaccount.myaccount" );
  con.setRequestProperty("Content­Type", "application/json");
  con.setRequestProperty("Content­Length", Integer.toString(json.getBytes().length));
  con.setRequestProperty("carriots.apikey", "here my api key");
  //con.setRequestProperty("ve", "HTTP/1.1");//some tests, with no positive results..
  //con.setRequestProperty("ur", "/streams");
  // Send post request
  DataOutputStream wr = new DataOutputStream(con.getOutputStream());
  System.out.println("Writing to the DataOutputStream");
  int responseCode = con.getResponseCode();
  BufferedReader in = new BufferedReader(
          new InputStreamReader(con.getInputStream()));
  String inputLine;
  StringBuffer response = new StringBuffer();
  while ((inputLine = in.readLine()) != null) {
  //print result


#2 saaiidmoran



  • Members
  • Pip
  • 1 posts

Posted 24 February 2018 - 10:40 PM

Your code is fine but, the only flaw is in the URL, as it is now = http://api.carriots.com/streams/

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users