I am banging my head against the HTTP.Post function.
The documentation says:
Performs an HTTP POST using the provided information against the passed URL. The function returns a JSON object containing a status value and the HTTP response.
This seems not to be the case...
Status code 200: all OK
var contentType = 'application/json',
url = 'https://httpbin.org/status/200';
try{
var req = HTTP.Post(url, contentType);
Write(Stringify(req));
} catch(e){
Write(Stringify(e));
}
Result:
{"StatusCode":200,"Response":[""]}
Status code 400: Throws error
var contentType = 'application/json',
url = 'https://httpbin.org/status/400';
try{
var req = HTTP.Post(url, contentType);
Write(Stringify(req));
} catch(e){
Write(Stringify(e));
}
Result:
{"message":"An error occurred when attempting to evaluate a HTTPPost function call. See inner exception for details.","description":"ExactTarget.OMM.FunctionExecutionException: An error occurred when attempting to evaluate a HTTPPost function call. See inner exception for details.\r\n Error Code: OMM_FUNC_EXEC_ERROR\r\n - from Jint --> \r\n\r\n --- inner exception 1---\r\n\r\nSystem.Net.WebException: The remote server returned an error: (400) Bad Request. - from System\r\n\r\n\r\n\r\n"}
I can fetch the error and handle it, but this is:
- not what the documentation says
- fetching the actual response will need regex and makes error handling harder
The same issue applies to Platform.Function.HTTPPost
Any ideas of why this is and if there is an alternative function which behaves differnetly?
Thank you