添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
So I want to modify a standard Http 200 response from a server, which contains headers and an image in the responsebody. I want to selectively replace that image (ideally from  a stored image file; but the actual image will change over time and/or I want to select different images based on logic). I want to retain the original headers from the server response, and replace the responsebody image. I would use the OnBeforeResponse event to trap the response. The images are standard files (image file only, no http headers).
I see I can load an entire response from a file with FildderScript, but I can't see how to load just the responsebody from a file (binary image jpg/or png or gif). I thought possibly I could populate an array from the image file, and then use ResponseBody:System.Byte[] call to attach the image (and fix up the headers associated with the size/content type etc).
I have searched far and wide but haven't found any related example FiddlerScript for this operation. Could you post a snippet along these lines?
If you want the client to see your changes, you must ensure that the specific session has streaming disabled (e.g. oSession.bBufferResponse = true); you can set this inside OnBeforeRequest or OnPeekAtResponseHeaders.
Replacing the body is trivial:
oSession.ResponseBody = File.ReadAllBytes("C:\\temp\\myimage.jpg");
The ResponseBody property setter will automatically correct the Content-Length and encoding related headers. If you change the MIME type (e.g. returning a JPG rather than a GIF) you may manually need to update the Content-Type header:
oSession.oResponse["Content-Type"] = "image/jpeg";
To use the File.ReadAllBytes method, you will need to ensure that you have
import System.IO
at the top of your script, and that the file path you use has all \ characters escaped to \\.
Regards,
Eric Lawrence
Telerik

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.