anyproxy 4.0怎么替换请求的域名

3ks5zfa0  于 2023-03-19  发布在  其他
关注(0)|答案(7)|浏览(135)

module.exports = {
*beforeSendRequest(requestDetail) {
if (requestDetail.url.indexOf(' https://ass.ds.net ') === 0) {
console.log(requestDetail.url);
const newRequestOptions = requestDetail.requestOptions;
requestDetail.protocol = 'http';
newRequestOptions.hostname = '123.12.221.56'
newRequestOptions.port = '9999';
newRequestOptions.method = 'GET';
console.log(requestDetail.url);
return requestDetail;
}
},

*beforeDealHttpsRequest(requestDetail) {
return true;
}
};
访问 https://ass.ds.net/date时,想在请求前修改访问的host,上面的方法修改成访问http://123.12.221.56:9999/date这个是可以成功的,但是host如果是域名,比如http://other.ss.net,这个时候把hostname改成other.ss.net无法访问到http://other.ss.net/date这个地址的数据。请问要怎么修改才可以

pb3skfrl

pb3skfrl1#

@codingfishman
改成域名后,接口改成了80,控制台会提示socket hang up,无法返回结果,不知道什么原因

q5lcpyga

q5lcpyga2#

直接 http://other.ss.net/data 是可以访问的对吧? 如果直接用node的http模块,或者 request 模块向 other.ss.net/data 访问会不会报错?

ltskdhd1

ltskdhd13#

@codingfishman
直接游览器打开是可以访问的,使用node的http模块也能访问成功

ars1skjm

ars1skjm4#

@wcycxp
这个就有些奇怪了,是不是 other.ss.net 做了 refer 之类的校验? 如果删除header里面相应的字段再代理到 other.ss.net 试试如何

fykwrbwg

fykwrbwg5#

@wcycxp 请问一下,这个问题最后解决了吗?

kgqe7b3p

kgqe7b3p6#

@xflife 还没有,前些时间比较忙,暂时就没有弄这个了

7kqas0il

7kqas0il7#

@wcycxp
改成域名后,请求报错了吗,返回了啥? 域名和ip应该是没有区别的, 另外端口也要设置成 "80"

相关问题