0 Replies Latest reply on Dec 29, 2015 2:04 AM by sreekarthik.k@gmail.com

    Http request not working

    Level 1

      the get http request is working but I need to  post the date via HTTP request. But the below request is not working any idea.

       

      var authStr = "kermit:admin@123";

      var encodedData = base64(authStr);

      var reply = "";

       

       

       

      var conn = new Socket;

      var request = "GET http://104.197.66.175:80/activiti-rest/service/runtime/tasks?processInstanceId=5001 HTTP/1.1\n"

                      + "Accept: application/json;\n"

                      + "Authorization: Basic "+ encodedData +"\n\n";

       

       

       

       

       

      if (conn.open ("104.197.66.175:80","UTF-8")) {

          conn.write (request);

          reply = conn.read(999999);

         conn.close();

          alert(reply);

         

       

       

      }

       

       

       

       

      conn1 = new Socket;  

      var input ="{\"action\":\"complete\",\"variables\":[{\"name\":\"image_process\",\"value\":\"true\"} ]}";

      var request = "POST http://104.197.66.175:80/activiti-rest/service/runtime/tasks/7510,"+ input +" HTTP/1.1\r\n"

                      + "Content-Type: application/json;\n"

                      + "Authorization: Basic "+ encodedData +"\n\n";

      $.writeln (request)

       

      if (conn1.open ("104.197.66.175:80", "UTF-8")) { 

      //    conn1.timeout=9000; 

          conn1.writeln (request)

          reply = conn1.read(999999);

         conn1.close();

          alert(reply);

         

         

       

       

       

       

      }

       

       

       

       

       

       

       

       

       

       

       

       

       

       

      function base64(binaryString) {

          var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

       

          var encoded = "";

          var c1, c2, c3;

          var e1, e2, e3, e4;

          var i = 0;

       

          while(i < binaryString.length) {

              c1 = binaryString.charCodeAt(i++);

              c2 = binaryString.charCodeAt(i++);

              c3 = binaryString.charCodeAt(i++);

       

              e1 = c1 >> 2;

              e2 = ((c1 & 3) << 4) | (c2 >> 4);

              e3 = ((c2 & 15) << 2) | (c3 >> 6);

              e4 = c3 & 63;

       

              if (isNaN(c2)) {

                  e3 = e4 = 64;

                  } else if (isNaN(c3)) {

                      e4 = 64;

                      }

              encoded = encoded + keyStr.charAt(e1) + keyStr.charAt(e2) +

                  keyStr.charAt(e3) + keyStr.charAt(e4);

              }

          return encoded;

          }