Hello, I am trying to use FiddlerScript to change a json response from my API server to my client. I keep on getting an error when I have my client connect to the server. I am new to FiddlerScript so I don't know if I am doing anything wrong.
This is the code I am using in Fiddler ScriptEditor:
01.// Here is code to modify server's response02.if(oSession.host == ("api.server") && oSession.uriContains("/config/url/1")) {03. // Color this response, so we can spot it in Fiddler04. oSession["ui-backcolor"] = "lime";05. 06. // Convert the request body into a string07. var oBody = System.Text.Encoding.UTF8.GetString(oSession.responseBodyBytes);08. 09. // Convert the text into a JSON object10. var j1 = Fiddler.WebFormats.JSON.JsonDecode(oBody);11. 12. //Change the value13. j1.JSONObject["data1"]["data2"]["data3"]["data4"]["Value"] = "1000";14. j1.JSONObject["data1"]["data2"]["data3"]["Value"] = "1000";15. 16. // Convert back to a byte array17. var modBytes1 = Fiddler.WebFormats.JSON.JsonEncode(j1.JSONObject);18. 19. // Convert json to bytes, storing the bytes in request body20. var mod = System.Text.Encoding.UTF8.GetBytes(modBytes1);21. oSession.RequestBody = mod;22.}23. 24.// Here is code to modify server's response25.if(oSession.host == ("api.server") && oSession.uriContains("/config/url/2")) {26. // Color this response, so we can spot it in Fiddler27. oSession["ui-backcolor"] = "lime";28. 29. // Convert the request body into a string30. var oBody = System.Text.Encoding.UTF8.GetString(oSession.responseBodyBytes);31. 32. // Convert the text into a JSON object33. var j2 = Fiddler.WebFormats.JSON.JsonDecode(oBody);34. 35. //Change the value36. j2.JSONObject["data1"]["data2"]["data3"]["data4"]["Value"] = "1000";37. j2.JSONObject["data1"]["data2"]["data3"]["Value"] = "1000";38. 39. // Convert back to a byte array40. var modBytes2 = Fiddler.WebFormats.JSON.JsonEncode(j2.JSONObject);41. 42. // Convert json to bytes, storing the bytes in request body43. var mod = System.Text.Encoding.UTF8.GetBytes(modBytes2);44. oSession.RequestBody = mod;45.}46. 47.// Here is code to modify server's response48.if(oSession.host == ("api.server") && oSession.uriContains("/config/database")) {49. // Color this response, so we can spot it in Fiddler50. oSession["ui-backcolor"] = "lime";51. FiddlerApplication.Log.LogFormat(oBody);52. 53. // Convert the request body into a string54. var oBody = System.Text.Encoding.UTF8.GetString(oSession.responseBodyBytes);55. 56. // Convert the text into a JSON object57. var j3 = Fiddler.WebFormats.JSON.JsonDecode(oBody);58. 59. //Change the value60. j3.JSONObject["Value"] = "1";61. j3.JSONObject["data1"]["Value"] = "1000";62. 63. // Convert back to a byte array64. var modBytes3 = Fiddler.WebFormats.JSON.JsonEncode(j3.JSONObject);65. 66. // Convert json to bytes, storing the bytes in request body67. var mod = System.Text.Encoding.UTF8.GetBytes(modBytes3);68. oSession.RequestBody = mod;69.}70. 71.// Here is code to modify server's response72.if(oSession.host == ("api.server") && oSession.uriContains("/config")) {73. // Color this response, so we can spot it in Fiddler74. oSession["ui-backcolor"] = "lime";75. 76. // Convert the request body into a string77. var oBody = System.Text.Encoding.UTF8.GetString(oSession.responseBodyBytes);78. 79. // Convert the text into a JSON object80. var j4 = Fiddler.WebFormats.JSON.JsonDecode(oBody);81. 82. //Change the value83. j4.JSONObject["Value"] = "1";84. j4.JSONObject["data1"]["Value"] = "1000";85. 86. // Convert back to a byte array87. var modBytes4 = Fiddler.WebFormats.JSON.JsonEncode(j4.JSONObject);88. 89. // Convert json to bytes, storing the bytes in request body90. var mod = System.Text.Encoding.UTF8.GetBytes(modBytes4);91. oSession.RequestBody = mod;92.}I have attached screenshots of the setup and the error codes.