我的Web API核心控制器的方法是这样的角2 http.post不使用Web API工作
public void Post(Sample sample) {
_sampleService.CreateSample(sample);
}
样品POCO看起来像这样
public class Sample : BaseEntity
{
public string BarCode { get; set; }
public DateTime CreatedAt { get; set; }
public virtual User CreatedBy { get; set; }
public virtual Status Status { get; set; }
}
客户端采样对象上仅发送2个属性现在看起来像这样。
{barcode:"1234"createdAt:"2017-06-07"}
和HTTP POST看起来像这样
createSample(sample: Sample) {
let headers = new Headers();
headers.append('Content-Type', 'application/json');
return this.http.post(AppConstants.createSample, JSON.stringify(sample), { headers: headers })
.map((res: Response) => res.json()); }
所以,如果我的用户头我没有得到任何“访问控制允许来源”标头现在
,如果我不使用页眉我得到(Unsupported Media Type)
任何想法这里发生了什么。 UPDATE 所以我也跟着在第一个答案说明,看起来像CORS未设置属性,但现在JSON没有被转换为C#对象
看起来像一个CORS问题。 –
没有CORS问题的其余呼叫正在工作。 CORS已全球启用 –