[英]How to send a Post request to the Pastebin API vie Code by Zapier and fetch?
[英]How to send fetch post request to an API key based authorized endpoint?
I have a .netcore web API application with several endpoints and I have a simple UI built to access an endpoint with a button click using javascript fetch API.
fetch('api/Sessions', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(callData)
})
.then(response => response.text())
.then((response) => updateResponse(response))
.catch(error => console.error(error));
}
现在 controller 中的 API 端点已使用 API-KEY 进行身份验证, [ServiceFilter(typeof(AuthorizeKey))]
我无法再从我的 UI 访问端点。 如何更改 HTML/javascript 代码以便将发布请求从我的 UI 发送到经过身份验证的端点? 谢谢
如果我错了,请纠正我。
fetch('api/Sessions', {
method: 'POST',
headers: {
'X-API-KEY': 'apikey',
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(callData)
})
.then(response => response.text())
.then((response) => updateResponse(response))
.catch(error => console.error(error));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.