gpt4 book ai didi

javascript - 带有 HTTP 请求 header 的 Parse.Cloud.httpRequest 调用

转载 作者:可可西里 更新时间:2023-11-01 16:48:09 24 4
gpt4 key购买 nike

我对云代码函数“Parse.Cloud.httpRequest”有疑问。我想像下面的 curl 命令一样发送 HTTP GET 请求。但它似乎不起作用。如果您发现问题,请帮助。

curl -H "Authorization: token xxx""https://api.automatic.com/v1/trips"

注意:

我的代码是这样的。然后我访问了/trips。

var express = require('express');
var app = express();

app.set('views', 'cloud/views');
app.set('view engine', 'ejs');
app.use(express.bodyParser());

app.get('/trips', function(req, res) {
Parse.Cloud.httpRequest({
url: 'https://api.automatic.com/v1/trips',
headers: {
'Authorization': 'token xxx'
},
success: function (httpResponse) {
console.log(httpResponse.text);
},
error: function (httpResponse) {
console.error('Request failed with response code ' + httpResponse.status);
}
});
});

app.listen();

这是一个日志。

E2014-07-16T04:10:46.102Z] v170: Ran custom endpoint with:
Input: {"method"=>"GET", "url"=>"/trips", "headers"=>{"version"=>"HTTP/1.1", "host"=>"easyparking.parseapp.com", "user-agent"=>"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36", "accept"=>"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", "accept-encoding"=>"gzip,deflate,sdch", "accept-language"=>"ja,en-US;q=0.8,en;q=0.6", "cache-control"=>"max-age=0", "x-forwarded-proto"=>"http"}}
Result: success/error was not called

最佳答案

试试这个修改:

app.get('/trips', function(req, res) {
Parse.Cloud.httpRequest({
url: 'https://api.automatic.com/v1/trips',
headers: {
'Authorization': 'token xxx'
}
}).then(function(httpResponse) {
console.log(httpResponse);
res.end(httpResponse.text);
}, function(err) {
console.log(err);
res.end(err);
});
});

关于javascript - 带有 HTTP 请求 header 的 Parse.Cloud.httpRequest 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24772571/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com