1 Reply Latest reply on Sep 18, 2015 4:44 AM by sreekarthik.k@gmail.com

    HTTP POST Request

    Level 1

      HTTP POST Request

       

       

      I need to HTTP POST to a webpage, and store server's output into a variable.

       

      here is the code. also i have copied the code from forum. But its not working. Any one have a idea how to post the data via scripting

       

       

       

       

       

       

      var response = make_HTTP_post('http://10.1.8.66',  ':8085/activiti-rest/service/runtime/process-instances',  { 'processDefinitionKey': 'photoshopTest',  'variables':[]  } ); 

       

       

      alert(response);    

       

      function make_HTTP_post(domain, path, post_data) { 

       

          var data_string = ''; 

          for ( var key in post_data ) { 

              if ( post_data.hasOwnProperty(key) ) { 

                  data_string += '&' + encodeURIComponent(key) 

                   + '=' + encodeURIComponent(post_data[key]); 

              } 

          } 

          data_string = data_string.substring(1); // discard first '&' 

       

          var conn = new Socket; 

          conn.open(domain + ':8085'); 

          conn.write('POST ' + path + " HTTP/1.1\r\n"); 

          conn.write('Host: ' + domain + "\r\n"); 

          conn.write('Content-Length: ' + data_string.length + "\r\n"); 

          conn.write("Content-Type: application/json\r\n"); 

          conn.write("\r\n");   

          conn.write(data_string);

          alert (data_string)

          var reply = '';

          reply = conn.read(999999);

          conn.close();

          reply = reply.split("\n\n");

          reply.splice(0,1); // discard server headers

       

          return reply.join("\n\n");