bounty将在2天后过期。回答此问题可获得+250声望奖励。Rilcon42希望引起更多人关注此问题。
我尝试更新一些旧代码来删除请求包,因为它不再被维护。我尝试用axios替换代理请求,但它不起作用(我只是得到了一个超时)。我是不是在哪里丢失了axios配置?使用请求包的示例工作正常。
未通过
export function sendAxiosApiRequest(enableProxy, proxyIndex,url,filepath?:string):object {
//https://support.zyte.com/support/discussions/topics/22000014602
let ca='READ IN FILE HERE'
let getOptions = {
url: url,
httpsAgent: tunnel.httpsOverHttp({
ca: ca,
proxy: {
host: 'http://MY_API_KEY:@proxy.crawlera.com',
port: '8011',
},
}),
proxy: false, //disable auto config, bc we set it manually
} as any;
console.log({getOptions})
return new Promise(resolve => {
try {
axios.get(getOptions,(err,response,html)=>{
if(err){
console.log(err);
resolve(false);
}
else {
try{
const output = JSON.parse(html);
resolve(output);
}catch(e){
console.log({html})
throw `ERROR parsing html: `+JSON.stringify(e)
}
}
})
}
catch (e) {
console.log(`Err parsing result from sendApiRequest:`,e);
resolve(false);
}
})
}
工程
export function sendRequestApiRequest(enableProxy, proxyIndex,url,filepath?:string):object {
let ca='READ IN FILE HERE'
let getOptions = {
url: url,
jar: true,
followAllRedirects: false,
} as any;
//console.log({filepath})
getOptions.proxy= 'http://MY_API_KEY:@proxy.crawlera.com'
getOptions.ca=ca
getOptions.requestCert =true
getOptions.rejectUnauthorized= true
return new Promise(resolve => {
try {
request.get(getOptions,(err,response,html)=>{
if(err){
console.log(err);
resolve(false);
}
else {
const output = JSON.parse(html);
resolve(output);
}
})
}
catch (e) {
console.log(e);
resolve(false);
}
})
}
1条答案
按热度按时间7hiiyaii1#
请看一下axios docs。get-requests的方法签名是
axios.get(url[, config])
,但您的第一个参数实际上是一个对象。您可能需要使用axios({})
并使用缺少的method
键更新您的getOptions
: