本文介绍在Fiddler中添加一键复制请求为cURL格式请求功能的方法。
Export to String
In many cases, you may wish to generate a string representing one or more Sessions in either HTTPArchive (HAR) or cURL format. While you can manually use File > Export to generate files of either format, you can now skip the middle-man and export to these types in memory. To do so, simply set the ExportToString option and do not set a Filename option. After the DoExport command completes, the output is found in the OutputAsString option.
For instance, you can add the following to your FiddlerScript:
BindUIButton("Copy HAR")
ContextAction("Copy HAR")
public static function doCopyHar(arrSess: Session[])
{
var oExportOptions = FiddlerObject.createDictionary();
// If you’d prefer to save to a file, set the Filename instead
//oExportOptions.Add("Filename", "C:\\users\\lawrence\\desktop\\out1.har");
oExportOptions.Add("ExportToString", "true");
oExportOptions.Add("MaxBinaryBodyLength", 1000000);
oExportOptions.Add("MaxTextBodyLength", 1000000);
FiddlerApplication.DoExport("HTTPArchive v1.2", arrSess, oExportOptions, null);
var sOutput: String = oExportOptions["OutputAsString"];
Utilities.CopyToClipboard(sOutput);
FiddlerApplication.UI.SetStatusText("Copied Sessions as HAR");
}
…and Fiddler will add a toolbar button and context menu command that copies the Selected Sessions to the clipboard in HAR format. (Tip: You can choose Edit > Paste As Sessions in Fiddler to create new Sessions based on HAR text that you’ve copied from browser tools.)
Alternatively, you can add a similar command to copy the Selected Sessions as a set of cURL commands:
BindUIButton("Copy cURL")
ContextAction("Copy cURL")
public static function doCopyCurl(arrSess: Session[])
{
var oExportOptions = FiddlerObject.createDictionary();
// If you'd prefer to save to a file, set the Filename instead
//oExportOptions.Add("Filename", "C:\\users\\lawrence\\desktop\\out1.bat");
oExportOptions.Add("ExportToString", "true");
FiddlerApplication.DoExport("cURL Script", arrSess, oExportOptions, null);
var sOutput: String = oExportOptions["OutputAsString"];
Utilities.CopyToClipboard(sOutput);
FiddlerApplication.UI.SetStatusText("Copied Sessions as cURL");
}
参考资料
-- EOF --
本文最后修改于6年前 (2019-07-16)