0

I have this code:

client (angular2) hosted on this url:

http://localhost:8080/Me/html/pages/gasolina/country/USA

code:

  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)

hosted on this url:

http://localhost:8080/Me/services/SaveConfig

code:

 @Path("/SaveConfig")
    @POST
    @Consumes(MediaType.APPLICATION_JSON + ";charset=utf-8")
    @Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
    public void saveConfig(CountryGasStationConfig countryGasStationConfig) throws Exception {

should i add these in jersy annotation?

When i run locally i get this error:

MLHttpRequest cannot load http://locahost:8080/.... Response for preflight is invalid (redirect)

I saw this post and this post

How can i make this solution in angular2?

app.

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 = {};
}]);
Community
  • 1
  • 1
Elad Benda2
  • 9,463
  • 23
  • 67
  • 138
  • It's unclear whether you're using angular2 or angularjs. Your http request at the top is angular2 while the config you're posting is angularjs. They're different frameworks and can't work together. Could you clarify? – Federico Pettinella Sep 24 '16 at 13:23
  • @FedericoP read the question again...it's quite clear – charlietfl Sep 24 '16 at 13:34
  • Try this - http://stackoverflow.com/questions/34464108/angular2-set-headers-for-every-request/34465070#34465070 – Parshwa Shah Sep 24 '16 at 14:22

0 Answers0