简体   繁体   中英

How can I save an HttpRequestMessage to file?

I am using OWIN to self host an API within a WPF application. This is for a tool for a tester who doesn't want to have to enable IIS7.

Inside my Post action I want to be able to save the HTTP Request ( ApiController.Request ) to a file like I can with System.Web.HttpRequest using SaveAs .

However OWIN doesn't provide HttpContext.Current (nor HttpContext.Current.Request ), it's null , and I can't find any other way to get at a System.Web.HttpRequest .

Is there a way I can save a System.Net.Http.HttpRequestMessage to a file, or just read it as text from a Stream ?

You can simply serialize any HttpRequestMessage and then store it wherever you want, eg in a text file. Later, you can read the file and deserialize its contents back into an HttpRequestMessage instance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM