我有这段代码:
托管在此网址上的客户端(angular2):
http://localhost:8080/Me/html/pages/gasolina/country/USA
代码:
return this.http
.post(this.supporToolSaveUrl, gasConfigModel, {headers: headers})
.map(res => res.json())
.subscribe(
data => {
console.info("next: ");
console.info(data)
},
err => console.error(err)
);
server(java jersey)
托管在此网址:
http://localhost:8080/Me/services/SaveConfig
代码:
@Path("/SaveConfig")
@POST
@Consumes(MediaType.APPLICATION_JSON + ";charset=utf-8")
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
public void saveConfig(CountryGasStationConfig countryGasStationConfig) throws Exception {
我应该在jersy注释中添加这些吗?
当我在本地运行时,我收到此错误:
MLHttpRequest cannot load http://locahost:8080/.... Response for preflight is invalid (redirect)
我看到了这个post和这篇帖子
我如何在angular2中制作此解决方案?
应用程序。
config(['$httpProvider', function ($httpProvider) {
//Reset headers to avoid OPTIONS request (aka preflight)
$httpProvider.defaults.headers.common = {};
$httpProvider.defaults.headers.post = {};
$httpProvider.defaults.headers.put = {};
$httpProvider.defaults.headers.patch = {};
}]);