admin管理员组文章数量:1126114
I'm using backbone in my website to access the Wordpress API. This works very nicely. However, it is my understanding that backbone always sends a nonce with each request.
This appears to be interfering with caching REST responses, as each request, with a nonce, is treated differently.
Is it possible to remove this nonce from the backbone request?
I'm using backbone in my website to access the Wordpress API. This works very nicely. However, it is my understanding that backbone always sends a nonce with each request.
This appears to be interfering with caching REST responses, as each request, with a nonce, is treated differently.
Is it possible to remove this nonce from the backbone request?
Share Improve this question asked Jan 21, 2024 at 12:46 MastaBabaMastaBaba 3113 silver badges12 bronze badges1 Answer
Reset to default 3Yes, the nonce is by default always being sent via the X-WP-Nonce
header – see the source here and here on GitHub.
wp.api.WPApiBaseModel.prototype.sync
and wp.api.WPApiBaseCollection.prototype.sync
can technically be extended or modified, but I would instead disable the nonce header like so, i.e. using <Collection or Model object>.endpointModel
:
Collection example:
const Posts = new wp.api.collections.Posts(); // Remove the nonce to disable the X-WP-Nonce header. Posts.endpointModel.set( 'nonce', '' ); //Posts.endpointModel.unset( 'nonce' ); // This also works. Posts.fetch( { data: { per_page: 2 }, } ).done( data => console.log( data ) );
Model example:
const Post = new wp.api.models.Post( { id: 1 } ); // Remove the nonce to disable the X-WP-Nonce header. Post.endpointModel.set( 'nonce', '' ); //Post.endpointModel.unset( 'nonce' ); // This also works. Post.fetch().done( data => console.log( data ) );
本文标签: rest apiUsing backbonecan I prevent the nonce from being set
版权声明:本文标题:rest api - Using backbone, can I prevent the nonce from being set? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736682461a1947493.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论