Notes:
- getHeaders method is defined on nlobjResponse object
- nlobjResponse object is created only by nlapiRequestURL
- getHeaders method is NOT available on nlobjRequest - e.g. on Suitelet request parameter
- getHeaders method returns an array. Each item of this array is a string
Sample code on how to list all headers:
function suitelet(request, response){ var res = nlapiRequestURL('URL'); // page is loaded and nlobjResponse object is stored in "res" var allHeaders = res.getAllHeaders(); // get all headers from the response //all headers will be shown in a table var out = '<table border="1">'; //run through all headers for(var h in allHeaders) { //we know that header 'Set-Cookie' is a header with multiple values if(allHeaders[h] == 'Set-Cookie') { //split the 'Set-Cookie' header var headers = res.getHeaders(allHeaders[h]); //run through all headers in the 'Set-Cookie' multi-valued header. hS is header name, headers[hS] is its value for(var hS in headers) { out += '<tr><th>' + hS + '</th><th>' + headers[hS] + '</th></tr>'; } } else { //single header out += '<tr><th>' + allHeaders[h] + '</th><td>' + res.getHeader(allHeaders[h]) + '</td></tr>'; } } out += '</table>'; response.writeLine(out);}
The example function can be used in Suitelets for testing HTTP headers of other NS pages or 3rd party applications.
No comments:
Post a Comment