最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Return 'X-WP-Total' from headers in response

programmeradmin1浏览0评论

I'm wondering if it's yet possible to get the value of 'X-WP-Total' in the api response.

Here is my request - axios.get(${url}/wp-json/wp/v2/media?per_page=100&mime_type=image/jpeg).then(response => this.photo = response.data);

which successfully returns all the images from the media library and stores them in an object named photo.

I can see the header value of 'X-WP-Total' in Postman, and I am hoping to return that value without having to create a custom endpoint, or touch the theme file

I'm wondering if it's yet possible to get the value of 'X-WP-Total' in the api response.

Here is my request - axios.get(${url}/wp-json/wp/v2/media?per_page=100&mime_type=image/jpeg).then(response => this.photo = response.data);

which successfully returns all the images from the media library and stores them in an object named photo.

I can see the header value of 'X-WP-Total' in Postman, and I am hoping to return that value without having to create a custom endpoint, or touch the theme file

Share Improve this question asked Jun 2, 2019 at 14:01 ElouiseElouise 11 silver badge1 bronze badge 1
  • If you can see those headers in postman then Axios will be getting them too, you just need to inspect the response object to see where Axios stores response headers – Tom J Nowell Commented Nov 17, 2020 at 12:30
Add a comment  | 

1 Answer 1

Reset to default 1

Ideally, you can access those headers with response.header, but not all headers are available publicly unless exposed manually. In your case, to access X-WP-Total by the client, you need to set the Access-Control-Expose-Headers header on your server:

Access-Control-Expose-Headers: X-WP-Total
发布评论

评论列表(0)

  1. 暂无评论