[英]How to setup twilio device in Angular app for the incoming call (i.e. API is in .NET 6)?
[英]how to call api in angular 10
我正在编写一个 Angular 网站,我正在尝试将一些有效负载发布到一个构建在 AWS 云上的 API。
我写了我的代码如下:
async doCognitoLogin(email, password) {
const payloads = {
poolData: {
UserPoolId: 'us-east-2',
ClientId: '324234234234sad',
Paranoia: '7',
},
params: {
username: 'myemail@yahoo.com',
password: '213123',
},
};
const url =
'https://fakeurl234.execute-api.us-east-2.amazonaws.com/Prod/signin';
let response = await fetch(url, {
method: 'POST', // *GET, POST, PUT, DELETE, etc.
mode: 'no-cors', // no-cors, *cors, same-origin
cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
credentials: 'same-origin', // include, *same-origin, omit
headers: {
'Content-Type': 'application/json',
// 'Content-Type': 'application/x-www-form-urlencoded',
},
redirect: 'follow', // manual, *follow, error
referrerPolicy: 'no-referrer', // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
body: JSON.stringify(payloads), // body data type must match "Content-Type" header
});
if (response.ok) {
// if HTTP-status is 200-299
// get the response body (the method explained below)
let json = await response.json();
} else {
alert('HTTP-Error: ' + response.status);
}
)
我在云监视中监控我的 API 输入和 output,我正在接收来自我的站点(本地主机)的请求,我正在记录来自我的 API 的响应,但我的代码没有收到 output,我只是遇到异常
HTTP 错误:0
我测试了我是否使用此网站 ( http://test-cors.org/ ) 配置了 cors,结果是正确的:
Sending POST request to https://fakesite1234.execute-api.us-east-2.amazonaws.com/Prod/signin
Fired XHR event: loadstart
Fired XHR event: readystatechange
Fired XHR event: readystatechange
Fired XHR event: progress
Fired XHR event: readystatechange
Fired XHR event: load
XHR status: 200
XHR status text:
XHR exposed response headers:
content-length: 3877
content-type: application/json
我的 API 在 POSTMAN 上运行良好,但在我的代码上运行不正常。 您介意帮我找出原因并帮我解决吗?
Angular提供HttpClient
进行请求,请参考https://angular.io/guide/http#making-a-post-request
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.