2014-12-22 43 views
0

我通過傳入序列化的JSON DTO來調用webapi上的發佈操作。WebApi自定義MediaTypeFormatter獲取發佈的參數

我也有一個自定義媒體類型格式化程序來加密結果數據。但是,在WriteToStreamAsync方法中,我如何獲取發佈的參數?

自定義介質類型格式化類

public class JsonFormatter : JsonMediaTypeFormatter 
{ 


    public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content, TransportContext transportContext) 
    { 
     var taskSource = new TaskCompletionSource<object>(); 
     try 
     { 
      if (value != null) 
      { 
       //How to get posted parameters? 
      } 
     } 
     catch (Exception e) 
     { 
      taskSource.SetException(e); 
     } 
     return taskSource.Task; 
    } 
} 

}

回答

0

我設法通過HttpContext.Current.Request.InputStream得到它