我有以下内容:
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, UriTemplate = "does/work")]
public bool DoesWork() {
bool Success = false;
IncomingWebRequestContext woc = WebOperationContext.Current.IncomingRequest;
return Success;
}
我可以通过POSTMAN成功发布,但无法获取以原始文本形式放置在正文中的json,如何在c#中以字符串形式获取数据?
谢谢
答案 0 :(得分:1)
尽管您在Post请求的正文中发送参数值,但是您需要通过方法parameter接受参数值。只需向您的方法添加参数,它就可以解决您的问题。
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, UriTemplate = "does/work")]
public bool DoesWork(WorkDetails workDetails) {
bool Success = false;
var work = worDetails.something; //if the type matches with your json content, you should have the values populated under work details
IncomingWebRequestContext woc = WebOperationContext.Current.IncomingRequest;
return Success;
}