![](/img/trans.png)
[英]How do i post the contents of a row from a table which is a response of a GET request from server?
[英]How do I get the contents of the response body of a GET request before the POST request fires? Can this be done with promise?
因此,我從前端接收JSON對象,並將其發送到后端的端點/ getData。 在這里,我使用GET請求從API獲取數據,並且需要在最終的POST請求中發送JSON對象和GET響應主體。 但是,當我發送請求時,GET響應的主體來不及,並且“ formInfo”未定義。
如何解決此問題,以便GET完成后發送POST請求?
app.post('/getData', function(req, res) {
debugger;
var data = req.body;
console.log(data);
toSend = data;
res.send({msg: "Success"});
var findID = {};
var endPoint = 'https://secure.p01.eloqua.com/API/REST/2.0/assets/form/' + toSend["formID"].toString();
var options = {
method: "GET",
headers: {'Authorization': authenticationHeader, 'Content-Type': 'application/json'}
};
request.get(endPoint, options, function (error, response, body) {
console.log(body);
findID = body["elements"];
request({
method: "POST",
headers: {'content-type': 'application/json', 'authorization': authenticationHeader},
url: 'http://localhost:3000/handleData',
json: {
"tuples": toSend,
"formInfo": body['elements']
}},
function (error, response, body) {
console.log(response);
});
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.