简体   繁体   English

如何使用 ServiceStack 访问响应标头

[英]How do I access the Response Headers using ServiceStack

I'm using react with Redux toolkit but I'm unbale to access the Response headers我正在使用 Redux 工具包做出反应,但我无法访问响应标头

return await client
.get(new Users())
.then((data) => {

// how to I access the Response Header here?
  console.log("data", data);
  return data;
})
.catch((error) => {

});

I'm assuming you're referring to ServiceStack's TypeScript Service Client , the public API of which you can find on index.d.ts where you can use the instance requestFilter and responseFilter :我假设您指的是ServiceStack 的 TypeScript 服务客户端,公共 API 您可以在index.d.ts上找到其中可以使用实例requestFilterresponseFilter

export declare class JsonServiceClient {
    //...
    requestFilter: (req: IRequestInit) => void;
    responseFilter: (res: Response) => void;
}

To inspect the underlying W3C fetch API's Request / Response , eg:检查底层 W3C fetch API 的Request / Response ,例如:

let client = new JsonServiceClient();
client.responseFilter = function(r) {
    console.log(r.headers)
}

client.get(new Users())
    .then(...)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Angular 5中使用HttpClient访问响应标头? - How do I access response headers using HttpClient in Angular 5? 如何从 Typescript 中的 fetch 调用迭代/访问响应标头? - How do I iterate/access response headers from a fetch call in Typescript? 如何访问通过管道传递到feedparser的请求的响应标头 - How can I access the response headers of a request that is piped to a feedparser 如何在没有标题的情况下提取响应内容(仅限正文)?使用Jquery - How do I extract the response content (only body) without headers? using Jquery 如何将响应和请求标头转换为 Javascript 中的数组缓冲区? - How do i convert response and request headers to arraybuffers in Javascript? CORS响应标头如何阻止浏览器JavaScript访问响应对象? - How do CORS response headers prevent browser javascript to access response object? 如何访问 Fetch 响应的负载 - How Do I Access the Payload of a Fetch Response 如何访问响应数组中的 promiseValue? - How do I access promiseValue in response array? 如何在Javascript中访问Websocket响应头? - How to access Websocket Response Headers in Javascript? 如何使用javascript访问AJAX未发送的HTTP响应标题? - How to access the headers a HTTP response that you didn't send by AJAX using javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM