Javascript 不匹配字符'';期待'\&引用';
我正在向代理发送请求,收到以下错误: {“error”:{“lang”:“en-US”,“description”:“查询语法错误”[第1:68行不匹配的字符“”应为“\”]“} 这是URL:Javascript 不匹配字符'';期待'\&引用';,javascript,fetch,yql,Javascript,Fetch,Yql,我正在向代理发送请求,收到以下错误: {“error”:{“lang”:“en-US”,“description”:“查询语法错误”[第1:68行不匹配的字符“”应为“\”]“} 这是URL: https://query.yahooapis.com/v1/public/yql?q=SELECT%20*%20FROM%20json%20WHERE%20url=%22https://1ex.trade/api/stats?market=BTC¤cy=CHBT%22&for
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);
}
});
});
};
您没有正确编码您的url,它应该是这样的
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
所以使用
您没有正确编码您的url,它应该是这样的
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
所以使用
我认为您需要正确编码url参数
exchangeUrl
中的符号(&)会打断q
参数,因此会打断您的查询
const yql_url = 'https://query.yahooapis.com/v1/public/yql?q=' +
'SELECT * FROM json WHERE url="' + encodeURIComponent(url) +
'"&format=json';
我认为您需要正确编码url参数
exchangeUrl
中的符号(&)会打断q
参数,因此会打断您的查询
const yql_url = 'https://query.yahooapis.com/v1/public/yql?q=' +
'SELECT * FROM json WHERE url="' + encodeURIComponent(url) +
'"&format=json';
需要对q URL中的&进行编码 例如:
需要对q URL中的&进行编码 例如: