anyproxy
anyproxy copied to clipboard
不能修改url,只能修改请求头。
Plese fill the template when you reporting a new issue, thanks!
Which platform are you running AnyProxy
Windows
The version of the AnyProxy
4.0.6
Your expected behavior of AnyProxy
我在试图用anyproxy修改url地址。 用官方文档里的 ···javascripty beforeSendRequest(requestDetail) { if (requestDetail.url.indexOf('https://httpbin.org/user-agent') === 0) { const newRequestOptions = requestDetail.requestOptions; requestDetail.protocol = 'http'; newRequestOptions.hostname = '127.0.0.1' newRequestOptions.port = '8008'; newRequestOptions.path = '/index.html'; newRequestOptions.method = 'GET'; return requestDetail; } }, ··· 这一段代码修改不了。 然后自己是了类似这样的代码、 ‘’‘javascript *beforeSendRequest(requestDetail) {
var url = requestDetail.url;
if (requestDetail.url.indexOf('cats') >=0 ) {
console.log('visited cats, going to dogs....')
var newUrl = 'http://localhost/dogs';
var newOptions = Object.assign({}, requestDetail.requestOptions);
newOptions.path = '/dogs'
console.log(newOptions);
return {
url: newUrl,
requestOptions: newOptions
};
}
},
''' 还是修改不了。有时候成功,请求cat跳转到dog,有时候还是跳转到cat。 我真在做爬虫,有些url参数很复杂,需要去掉一笑参数。然后看结果。
The actual behavior of AnyProxy
Anyproxy 不能修改url地址。
The log of the error
@neverusedname 官方示例里面的代码,修改后的请求是错误的地方还是说没有生效? 直接修改url是不会生效的,需要修改里面对应的path、host等信息,同时你可以拿到已有的path,并对参数做过滤,可否也提供一下不生效的那段代码?
你好,修改path host都不会生效。应该是一个bug。试过多次,有时候能够重定向。有时候无效。
console.log('Getting advertisement content...')
// delete referer delete requestDetail.requestOptions.headers['Referer'];
delete params var url = requestDetail.url; var paramsToDelete = ['appmsg_type', 'uin', 'ct', 'both_ad', 'title', 'version', 'wxtoken', 'clientversion', 'comment_id', 'is_original', 'devicetype', 'key', 'is_need_reward', 'reward_uin_count', 'r', 'msg_daily_idx' ]; var cleanUrl = someCleanUrl; return resetUrl(requestDetail, cleanUrl);
function resetUrl(requestDetail, newUrl){ var newOptions = Object.assign({}, requestDetail.requestOptions); var newPath = getPath(newUrl); newOptions.path = newPath; var newReq = { url: newUrl, requestOptions: newOptions }; console.log(newReq); return newReq;
var response = { response: { statusCode: 302, header: { 'liu-intercepted': 'true', 'content-type': 'text/plain'}, } }; };
在 2018-03-28 19:44:10,"Nick" [email protected] 写道:
@neverusedname 官方示例里面的代码,修改后的请求是错误的地方还是说没有生效? 直接修改url是不会生效的,需要修改里面对应的path、host等信息,同时你可以拿到已有的path,并对参数做过滤,可否也提供一下不生效的那段代码?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
听你描述应该确实像是触发了特定的逻辑,不过没还有遇到过。 你的rule代码修改了path,其他信息没变,讲道理是会到新的path中去的,可否提供完整的beforeSendRequest方法? 具体url可以隐去
你好,非常感谢您的支持。 我试图拦截对某个网站的请求,分析这些参数的作用。 这是是一个post请求,但是url里面也带了参数。 试图1)删除post请求体里面的body 2)删除部分url里的参数 3)删除一些请求头。
现在只有删除请求头有效,其他2个无效。代码是这样的。
module.exports =
// big before send request
*beforeSendRequest(requestDetail) {
if(requestDetail.url.indexOf('someurl?a=a1&b=b1&c=c1&d=d1') >= 0) {
// Delete header works
delete requestDetail.requestOptions.headers['Referer'];
// It's a post method, attempts to delete post data
// This delete requestData won't work eigher
delete requestDetail.requestData;
// params too messy, clean it and check how params work.
var url = requestDetail.url;
var paramsToDelete = ['b', 'c'];
var cleanUrl = deleteParams(url, paramsToDelete);
// This reset url won't work either.
return resetUrl(requestDetail, cleanUrl);
}
}
};
function deleteParams(url, params){
// can only delete params between two &, e.g. hell?&a=a1&b=b1&c=c1
// only b=b1 will be deleted. a, c will remain.
var resUrl = url;
for(var i=0;i<params.length;i++){
resUrl = deleteOneParam(resUrl, params[i]);
}
return resUrl;
};
function deleteOneParam(url, param){
// can only delete params between two &, e.g. hell?&a=a1&b=b1&c=c1
// only b=b1 will be deleted. a, c will remain.
var pat = '(?<=\&)'+param+'=.*?(?=\&)';
var ss = url.match(pat);
if(ss){
var s = ss[0];
return url.replace(s+'&', '');
}
return url;
};
function resetUrl(requestDetail, newUrl){
var newOptions = Object.assign({}, requestDetail.requestOptions);
var newPath = getPath(newUrl);
newOptions.path = newPath;
var newReq = {
url: newUrl,
requestOptions: newOptions
};
console.log(newReq);
return newReq;
};
function getPath(url){
var pat = '//.+?/';
var ss = url.match(pat);
if(ss){
var n = ss[0].length;
var i = ss.index;
return url.substring(n+i-1);
}
return '/'
};
@neverusedname 将你的代码执行了一下,有几点可以得出:
- 直接删除
requestDetail.requestData确实会无效,因为AnyProxy在发现requestData为空时,会用原始的requestData来替代,这个我们将进行修复。 同时你也可以将其改为一个无效但是有值的requestData - 修改url是可以的,我将path简单的修改(而不是执行了你的url去参数的方法),确认是以新的url进行请求,服务器会拿到不带参数的请求。 因此会不会是
deleteParams + getPath方法返回的url也是带参数的?这个你可以确认一下,或者强行将path手写成一个地址,看看是否生效
楼主问题解决了吗,我现在使用url、path也是更改不起作用
没有,后来我放弃了发自我的华为手机-------- 原始邮件 --------发件人: zhengzhengde [email protected]日期: 2019年5月24日周五 上午10:58收件人: alibaba/anyproxy [email protected]抄送: Liu Hao [email protected], Mention [email protected]主 题: Re: [alibaba/anyproxy] 不能修改url,只能修改请求头。 (#354)楼主问题解决了吗,我现在使用url、path也是更改不起作用
—You are receiving this because you were mentioned.Reply to this email directly, view it on GitHub, or mute the thread.
可以试试mitmproxy发自我的华为手机-------- 原始邮件 --------发件人: zhengzhengde [email protected]日期: 2019年5月24日周五 上午10:58收件人: alibaba/anyproxy [email protected]抄送: Liu Hao [email protected], Mention [email protected]主 题: Re: [alibaba/anyproxy] 不能修改url,只能修改请求头。 (#354)楼主问题解决了吗,我现在使用url、path也是更改不起作用
—You are receiving this because you were mentioned.Reply to this email directly, view it on GitHub, or mute the thread.