request.setHeader(name, value)


为请求头对象设置请求头的值。 如果请求头已存在则替换。 使用字符串数组可以发送多个同名的请求头。 非字符串的值会保留原样,所以 request.getHeader() 会返回非字符串的值。 非字符串的值在网络传输时会转换为字符串。

例子:

request.setHeader('Content-Type', 'application/json');

或:

request.setHeader('Set-Cookie', ['type=ninja', 'language=javascript']);

Sets a single header value for headers object. If this header already exists in the to-be-sent headers, its value will be replaced. Use an array of strings here to send multiple headers with the same name. Non-string values will be stored without modification. Therefore, request.getHeader() may return non-string values. However, the non-string values will be converted to strings for network transmission.

request.setHeader('Content-Type', 'application/json');

or

request.setHeader('Cookie', ['type=ninja', 'language=javascript']);