2014-12-04 34 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