C# Wcf POST 值

标签 c# wcf

我想接收由 html 表单发送的 POST 请求。

    [OperationContract(Name = "post_test")]
    [WebInvoke(
        Method = "POST",
        UriTemplate = "post",
        ResponseFormat = WebMessageFormat.Json)]
    Result postMth(Stream stream);


    public Result postMth(Stream stream)
    {
        StreamReader reader = new StreamReader(stream);
        string data = reader.ReadToEnd();
        reader.Close();
        NameValueCollection post = HttpUtility.ParseQueryString(data);
        throw new Exception("Value = " + post["mypost"]);
    }

我如何接收通过我的表单发送的 POST var?

数据结果:

------WebKitFormBoundary24UETQYkoz77p3Tt
Content-Disposition: form-data; name="mypost"

some text

最佳答案

尝试在您的 postMth 中使用此代码:

MultipartParser parser = new MultipartParser(stream);
if (parser.Success)
{
    // Put your code here
}

MultipartParser 库是一个简单的类,它解析包含二进制数据的多部分表单数据并返回文件流。

MultipartParser @ CodePlex

关于C# Wcf POST 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27305693/

相关文章:

c# - 手机进入休眠状态后,在前台服务中保持 wifi 处于 Activity 状态

c# - 在 UWP 中添加图像?

c# - 在派生对象中使用比父对象定义的类型更强的列表

c# - 如何使用 WSDL 文件在 Visual Studio.NET 中创建 Web 服务?

mysql - 如何分离这两个过程?

c# - 运行局域网 WCF 服务

c# - 在 WebAPI C# 中请求反序列化期间捕获异常

c# - Azure函数: Is there optimal way to upload file without storing it in process memory?

wcf - 委托(delegate)和 WCF 方法

wcf - 大型 WCF 服务的最佳实践?