2014-12-04 49 views
2

我想收到一个由HTML表单发送的POST请求。C#Wcf 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 

回答

2

postMth与此代码尝试:

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

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

MultipartParser @ CodePlex

+0

我不希望保存的内容。我只想得到我的POST – Sancho 2014-12-04 23:00:07

+0

好吧,比放入一些其他代码。 – TheLittleHawk 2014-12-04 23:00:31