我有一个.net/C#的Web API 2.0 REST服务,它工作正常,如果有邮差的测试,但如果总是得到空参数从Angular2通话/ 4与邮政的http服务。Angular2/4 HTTP POST服务调用的.Net/MVC的Web API 2.0 REST参数为空
下面是代码:
C#:
public class UsersController : ApiController
{
// POST: api/users/login
public string login([FromBody]string value)
{
var ss = value;
return value;
}
}
Angular2服务:
login(email: string, password: string) {
const headers: Headers = new Headers();
headers.append('Content-Type', 'application/json');
const theBody = {'email': email, 'password': password};
const requestoptions: RequestOptions = new RequestOptions({
method: RequestMethod.Post,
url: this.host + '/users/login',
headers: headers,
body: JSON.stringify(theBody)
})
return this.http.request(new Request(requestoptions))
.map((res: Response) => {
return res.json;
})
.catch(this.logAndPassOn);
}
当与邮差测试,我设置标头,如内容类型:应用/ JSON和体选择 “原始”。
一切看起来是一样的,但是Angular2 HTTP POST服务不反正工作,我总是得到空值。
在此先感谢您的任何帮助。
你在邮差中发送的JSON是什么样的? –
你在组件或服务中获得了零组件? –
你使用'[HttpPost]'吗? –