4

特定の 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": "test@test.us",
        "firstName": "test",
        "lastName": "test",
        "id": 52352352,
        "uuid": "5631f-grdeh4",
        "isAdmin": false
    }
}

isAdminリクエストをインターセプトして trueに変更する必要があります。

また、特定の URL ( https://test.com/profiles/{Random_Numbers}/{id}) への GET 要求には、次のような (エンコードされた) 応答があります。

{
    "id": 0, 
    "Code": "Admin", 
    "display": "RRRR"
}

5に変更idする必要があります。

したがって、基本的には、これらの両方のアクションを実行する 1 つのスクリプトを作成する必要があります。

これまでのところ、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-request と response を取得する方が良いでしょう。

4

1 に答える 1

10

あなたが投稿したスクリプトと Python の JSON モジュールは、あなたをかなり遠くまで連れて行ってくれるはずです:

def response(context, flow):
    if flow.request.url == "...": # optionally filter based on some criteria...
        with decoded(flow.response):  # automatically decode gzipped responses.
            data = json.loads(flow.response.content)
            data["foo"] = "bar"
            flow.response.content = json.dumps(data)
于 2015-04-28T08:43:43.420 に答える