« Back to full topics list
0
0

Hi,

I need some help. I’m trying the below code:

I tried the following script.

var test = "abc"
  return http.request({
    url: "http://mysterious-sierra-8455.herokuapp.com/abcd",
    method : 'PUT',
   headers : {
      "Content-Type": 'application/json',
      "Content-Length": "3"
    },
    "rawBody": test
  });

But I am getting anthe following error:

{
	"metadata": {
		"requestId": "f9908459-9bd2-4bdd-99d2-a83ca518b1a4",
		"status": "success",
		"statusCode": "200"
	},
	"result": {
		"metadata": {
			"status": "failure",
			"errorCode": "HTTP_PROTOCOL_ERROR"
		}
	}
}

Can you tell me what’s wrong?

ANSWERED
Marked as spam
Posted by - Asked on December 17, 2016 10:31 pm - 46 views

1 Replies

0
Private reply

Hello Wendy,

There are two things that you need to fix in your code:

1) Scriptr.io automatically calculates the content-length of your content, so you should not pass the content-length header field yourself.
2) There is a mistake in your code. You are sending “rawBody” instead of “bodyString” as in the below:

var test = "foo bar";

return http.request({
	url : "http://mysterious-sierra-8455.herokuapp.com/abcd",
	method : 'PUT',
	headers : {
		"Content-Type" : 'application/json',
	},
	"bodyString" : test
});

Please note that “rawBody” is for the “request” object not for “http”. Replace rawBody with bodyString and your code should work fine.

Regards,

Julien Mrad
Scriptr.io

Marked as spam
Posted by - Replied on December 18, 2016 9:34 am