发送到特定 URL 的 POST 请求(http://test.com
)看起来像这样:
{
"messageType": "OK",
"city": {
"Name": "Paris",
"Views": {
"1231": {
"id": 4234,
"enableView": false
},
},
"Views": [5447, 8457],
"messages": [{
"id": "message_6443",
"eTag": 756754338
}]
},
"client": {
"Id": 53,
"email": "[email protected]",
"firstName": "test",
"lastName": "test",
"id": 52352352,
"uuid": "5631f-grdeh4",
"isAdmin": false
}
}
我需要拦截请求并更改isAdmin
为真。
以及对某个 URL 的 GET 请求(https://test.com/profiles/{Random_Numbers}/{id}
)有一个(编码的)响应,如下所示:
{
"id": 0,
"Code": "Admin",
"display": "RRRR"
}
我需要改变id
to 5.
所以基本上我需要编写一个脚本来执行这两项操作。
到目前为止,我已经尝试利用 GitHub 上的一些示例,但到目前为止我还没有得到它:
from libmproxy.protocol.http import decoded
def start(context, argv):
if len(argv) != 3:
raise ValueError('Usage: -s "modify-response-body.py old new"')
context.old, context.new = argv[1], argv[2]
def response(context, flow):
with decoded(flow.response): # automatically decode gzipped responses.
flow.response.content = flow.response.content.replace(context.old, context.new)`
我如何在我的场景中实现这一点?
也许使用 libmproxy 来获取 http 请求和响应会是一个更好的主意。