我正在向代理发送请求,我收到此错误:
{"错误":{" lang":" zh-CN","说明":"查询语法错误(s)[第1:68行不匹配的字符' '期待' \"']"}}
这是网址:
https://query.yahooapis.com/v1/public/yql?q=SELECT%20*%20FROM%20json%20WHERE%20url=%22https://1ex.trade/api/stats?market=BTC¤cy=CHBT%22&format=json
有没有人知道我做错了什么?
这是我在JS的请求
let fetchRequestForGettingTheNamesTroughProxy = function (exchangeUrl) {
return new Promise(function (resolve, reject) {
const url = exchangeUrl;
const yql_url = 'https://query.yahooapis.com/v1/public/yql?q=' + 'SELECT * FROM json WHERE url="' + url + '"&format=json';
let request = new Request(yql_url, {
method: 'POST',
headers: new Headers()
});
fetch(request)
.then((resp) => resp.json())
.then(function (data) {
console.log(data.query.results);
if (data.query.results === null){
fetchRequestForGettingTheNamesTroughProxy(exchangeUrl);
} else{
resolve(data.query.results.json);
}
});
});
};
答案 0 :(得分:1)
您没有正确编码您应该看起来像
的网址https://query.yahooapis.com/v1/public/yql?q=SELECT%20*%20FROM%20json%20WHERE%20url=%27https%3A%2F%2F1ex.trade%2Fapi%2Fstats%3Fmarket%3DBTC%26currency%3DCHBT%27&format=json
所以请使用encodeURIComponent
const yql_url = 'https://query.yahooapis.com/v1/public/yql?q=' + 'SELECT * FROM json WHERE url="' + encodeURIComponent(url) + '"&format=json';
答案 1 :(得分:1)
我认为您需要正确编码url参数
exchangeUrl
中的&符号(&)会破坏q
参数,从而中断您的查询。
const yql_url = 'https://query.yahooapis.com/v1/public/yql?q=' +
'SELECT * FROM json WHERE url="' + encodeURIComponent(url) +
'"&format=json';
答案 2 :(得分:1)
&在您的q网址中需要进行编码。
EG:
https://query.yahooapis.com/v1/public/yql?q=SELECT%20*%20FROM%20json%20WHERE%20url=%22https://1ex.trade/api/stats?market=BTC%26currency=CHBT%22&format=json