我想接收由 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 库是一个简单的类,它解析包含二进制数据的多部分表单数据并返回文件流。
关于C# Wcf POST 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27305693/