1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Fiddlerでレスポンスを置き換える

Last updated at Posted at 2020-07-13

初めてFiddlerを使い、カスタムスクリプトでレスポンスを書き換えようと思ったのですが、うまくいかず苦労したのでメモを残します。
※もっと良い方法があれば教えていただきたいです

やりたかったこと

{
  data: [
    {
      hoge: "abcde",
    },
    {
      geho: "12345",
    }
  ]
}

上記のレスポンスが来た時に、下記のように書き換えるようなことがしたかった

{
  data: [
    {
      hoge: "abcde",
      fuga: [ // ここから
        {
          hogehoge: "fugafuga"
        },
        {
          hogehoge2: "fugafuga2"
        },
      ] // ここまで追加
    },
  ]
}

解決

static function OnBeforeResponse(oSession: Session) {
    var response = Fiddler.WebFormats.JSON.JsonDecode(oSession.GetResponseBodyAsString());
    response.JSONObject["data"][fuga] = Fiddler.WebFormats.JSON.JsonDecode('[{},{}]').JSONObject;
    response.JSONObject["data"][fuga][0]["hogehoge"] = "fugafuga";
    response.JSONObject["data"][fuga][1]["hogehoge2"] = "fugafuga2";

  oSession.utilSetResponseBody(Fiddler.WebFormats.JSON.JsonDecode(response));
}

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?