我想将从POST请求中收到的响应(身份验证令牌)用于新的GET请求。如何存储此响应并将其用于其他请求?
响应如下:
{
"Code": 1,
"Data": {
"Email": "myEmail",
"Token": "e92215042ec440579686b2de9f191f84",
"BasicAuth": "Basic bWFhcnRqZS52YW5kZXJiaWVAZ21haWwuY29tOmU5MjIxNTA0MmVjNDQwNTc5Njg2YjJkZTlmMTkxZjg0"
}
}
我正在使用Postman测试我的API调用,并且一切正常。在测试代码中,我使用
var responseData = pm.response.json();
console.log(responseData);
postman.setEnvironmentVariable("token_closet", responseData.Data.BasicAuth);
设置一个新变量,并在下一个请求中使用该变量。如何在javascript中做到这一点?这就是我现在在javascript中所拥有的。
var settings = {
"async": true,
"crossDomain": true,
"url": "https://www.clo-set.com/api/Account/Login",
"method": "POST",
"headers": {
"Content-Type": "application/json",
"Accept": "application/json",
},
"processData": false,
"data": "{\n\t\"Email\":\"myEmail\",\n\t\"Password\":\"myPassword\"\n}"
}
$.ajax(settings).done(function (response) {
console.log(response);
});