Parse.Cloud.httpRequest httpresponse与cUrl响应不匹配
我希望从Parse.com调用Parse.cloud.httpRequest的云代码中得到与从cUrl中得到的相同的HTTP响应。但是我不能得到它。有人知道我做错了什么吗 卷曲示例:Parse.Cloud.httpRequest httpresponse与cUrl响应不匹配,curl,parse-platform,bitcoin,chain,Curl,Parse Platform,Bitcoin,Chain,我希望从Parse.com调用Parse.cloud.httpRequest的云代码中得到与从cUrl中得到的相同的HTTP响应。但是我不能得到它。有人知道我做错了什么吗 卷曲示例: curl https://api.chain.com/v2/bitcoin/transactions/917673efa435b483343ddfe373995df365260c617107d3f9de68abd4e97c981b/confidence?api-key-id=e8d5ed773cf24e31c149
curl https://api.chain.com/v2/bitcoin/transactions/917673efa435b483343ddfe373995df365260c617107d3f9de68abd4e97c981b/confidence?api-key-id=e8d5ed773cf24e31c149ae874eb23c74
cUrl的答复:
{
"transaction_hash":"917673efa435b483343ddfe373995df365260c617107d3f9de68abd4e97c981b",
"block_hash":"0000000000000000042568aae3c297f687caa1b7737d8dab8e7d7b5087fb87f5",
"propagation_level":null,
"double_spend":null
}
解析云代码示例:
Parse.Cloud.httpRequest({
method: 'GET',
url: "https://api.chain.com/v2/bitcoin/transactions/917673efa435b483343ddfe373995df365260c617107d3f9de68abd4e97c981b/confidence",
params: {
"api-key-id": "e8d5ed773cf24e31c149ae874eb23c74"
},
headers: {
'Content-Type': 'application/json'
}
}).then(function (httpResponse) {
console.log("httpResponse:");
console.log("status:" + httpResponse.status);
console.log("text:" + httpResponse.text);
console.log("headers:");
console.log(httpResponse.headers);
}, function (httpResponseError) {
console.error('httpResponse failed with response code ');
console.log(httpResponseError);
});
解析中HTTP响应的日志如下所示:
I2015-05-28T15:49:12.545Z]httpResponse:
I2015-05-28T15:49:12.547Z]status: 200
I2015-05-28T15:49:12.549Z]text: \
0D%gM?#M-
QR^:0觹ovҦٌ&YZȁg~}m%H,N-p]%DD%
qTdG,|֟u[VeՇV3rpi_w{
I2015-05-28T15:49:12.549Z]headers:
I2015-05-28T15:49:12.550Z]{"Access-Control-Allow-Credentials":"true","Access-Control-Allow-Methods":"GET,POST,PATCH,PUT,DELETE,OPTIONS,HEAD","Access-Control-Allow-Origin":"","Access-Control-Expose-Headers":"Next-Range","Connection":"keep-alive","Content-Encoding":"gzip","Content-Length":"187","Content-Type":"application/json; charset=utf-8","Date":"Thu, 28 May 2015 15:49:12 GMT","Server":"Cowboy","Strict-Transport-Security":"max-age=31536000","Vary":"Accept-Encoding","Via":"1.1 vegur","X-Content-Type-Options":"nosniff","X-Frame-Options":"SAMEORIGIN","X-Request-Id":"e2c69578-635d-4d6c-85bf-f1b0e314ea58","X-Runtime":"0.008468","X-Xss-Protection":"1; mode=block"}
我在响应的解析日志中看到无法读取的数据。有可能修复它吗?内容是gzip编码的。线索在响应头中-有一个“内容编码”:“gzip”头返回 如果希望CURL中的输出相同,请尝试以下命令
curl -X "GET" "https://api.chain.com/v2/bitcoin/transactions/917673efa435b483343ddfe373995df365260c617107d3f9de68abd4e97c981b/confidence?api-key-id=e8d5ed773cf24e31c149ae874eb23c74" \
-H "Accept-Encoding: gzip" \
-H "Content-Type: application/json"
您可以通过在Accept encoding标头中传递标识来关闭gzip编码
curl -X "GET" "https://api.chain.com/v2/bitcoin/transactions/917673efa435b483343ddfe373995df365260c617107d3f9de68abd4e97c981b/confidence?api-key-id=e8d5ed773cf24e31c149ae874eb23c74" \
-H "Accept-Encoding: identity" \
-H "Content-Type: application/json"
或者在你的云代码中
Parse.Cloud.httpRequest({
method: 'GET',
url: "https://api.chain.com/v2/bitcoin/transactions/917673efa435b483343ddfe373995df365260c617107d3f9de68abd4e97c981b/confidence",
params: {
"api-key-id": "e8d5ed773cf24e31c149ae874eb23c74"
},
headers: {
'Content-Type': 'application/json',
'Accept-Encoding': 'identity'
}
}).then(function (httpResponse) {
....
我还没有对此进行测试,但希望Parse不会覆盖您设置的值