首页 新闻 会员 周边

webapi httpclient post 参数问题

0
悬赏园豆:30 [待解决问题]

public class KeywordController : ApiController {

[System.Web.Http.HttpPost]
public bool Post(KeywordInfo obj) {
  var v = obj.SearchWord;

  return true;

}

}

 

public static async Task<string> PostAsync(string url, object obj) {
using (var content = new StringContent(obj.ToJson())) {
var response = await _client.PostAsync(url, content);
response.EnsureSuccessStatusCode();
return await response.Content.ReadAsStringAsync();
}
}

 

HttpClientHelper.PostAsync("http://localhost:8098/api/keyword", new KeywordInfo { SearchWord = word });

 

POST方法断点断不到,似乎参数没有接收到。

老S的主页 老S | 初学一级 | 园豆:11
提问于:2017-06-17 13:42
< >
分享
所有回答(2)
0

([frombody]KeywordInfo obj)

吴瑞祥 | 园豆:29449 (高人七级) | 2017-06-17 15:09

 试过了,一样收不到。

支持(0) 反对(0) 老S | 园豆:11 (初学一级) | 2017-06-17 15:59
0

自己解决了,郁闷,折腾了一天。

老S | 园豆:11 (初学一级) | 2017-06-18 07:58
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册