我想向具有字符串作为其参数的C#服务发送请求。我写了这样的角度服务:
export class CategoryService {
constructor(private http: HttpClient) { }
getCategory(categoryName: string): Observable<Category> {
console.log(categoryName);
return this.http.post("/category/GetCategory", { categoryName: categoryName }, { headers: new HttpHeaders({ 'Content-type': 'application/json' }) });
}
我也尝试过:
export class CategoryService {
constructor(private http: HttpClient) { }
getCategory(categoryName: string): Observable<Category> {
console.log(categoryName);
return this.http.post("/category/GetCategory", categoryName , { headers: new HttpHeaders({ 'Content-type': 'application/json' }) });
}
但是,当他们俩都成功发送请求时,该参数始终为null。我的C#服务是:
[HttpPost]
public IActionResult GetCategory([FromBody]string categoryName)
我在这里找到了解决方案:Angular2-Http POST请求参数我也应该从我的服务参数中删除[FromBody]。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句