我试图拦截和修改graphql响应的主体。这是我的密码:
from mitmproxy import ctx
from mitmproxy import http
import json
def response(flow: http.HTTPFlow) -> None:
if flow.request.pretty_url == "https://my.graphql/endpoint":
request_data = json.loads(flow.request.get_text())
if request_data["operationName"] == "MyOperationName":
data = json.loads(flow.response.get_text())
data["data"]["product"]["name"] = "New Name"
flow.response.text = json.dumps(data)我可以在mitmproxy控制台中看到修改后的响应。但是我使用的iOS模拟器仍然得到了最初的响应。有人知道如何将修改后的响应传递给设备吗?
发布于 2022-02-23 14:27:36
从文件中
def response(self, flow: mitmproxy.http.HTTPFlow):
"""
The full HTTP response has been read.
Note: If response streaming is active, this event fires after the entire body has been streamed.
HTTP trailers, if present, have not been transmitted to the client yet and can still be modified.
"""
ctx.log(f"response: {flow=}")您可能会对响应体进行流处理,这意味着修改将被忽略。
考虑使用def request事件钩子代替
https://stackoverflow.com/questions/68018729
复制相似问题