Parsing “multipart/form-data” in .NET/C#

后端 未结 2 1218
小鲜肉
小鲜肉 2021-02-09 02:07

Got a .NET/C# question...

I need to parse some input post data thats in a \"multipart/form-data\" format to extract the passed username and password. Anyone know how to

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-09 02:22

    Marc's got it. The easiest way to use the ASP.NET compatibility requirements mode is to apply the AspNetCompatibilityRequirementsMode attribute on your operation. Then you have access to the HttpContext form params. Here's how you'd go about it:

            [OperationContract]
            [WebInvoke(Method = "POST", 
                        UriTemplate = "Login", 
                        BodyStyle = WebMessageBodyStyle.Bare)]
            [AspNetCompatibilityRequirements(RequirementsMode = 
                        AspNetCompatibilityRequirementsMode.Required)]
            public Stream Login(Stream input)
            {
                string username = HttpContext.Current.Request.Params["username"];
                string password = HttpContext.Current.Request.Params["password"];
            }
    

提交回复
热议问题