I have tried to look for answer, some are close but not what I am looking for.
This is my issue, I am developing an Ionic app and currently devving in the web browser view. I am unable to post any content back to my asp dotnet core backend.
My stack is as follows: Front-End
- Ionic 2 - Latest version using latest version of Angular 4
- Nginx - as my proxy server
- Docker - as my container running dotnet core applications
Here is the code for the post I am trying:
let body =JSON.stringify({ 'username': username, 'password': password });
let options = new RequestOptions({headers:new Headers()});
options.headers.set('Content-Type', 'application/json; charset=UTF-8');
options.headers.set( 'Accept', 'application/json' );
return this.http.post(this.loginUrl,body,options)
.map((res: Response) => res.json())
.catch((error: any) => {
console.log("ERROR", error);
return Observable.throw(error.json().error || 'Server error')
})
My Proxy has
add_header 'Access-Control-Allow-Origin' *;
And my backed has the following CORS configuration in Startup.cs
options.AddPolicy("CorsPolicy",
builder => builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials());
});
and in the Configure function
app.UseMvc().UseCors("CorsPolicy");
I see in the output window in Visual Studio 2017 that the response is reaching the container:
Application Insights Telemetry (unconfigured): {"name":"Microsoft.ApplicationInsights.Dev.Request","time":"2017-07-15T19:29:10.5330300Z","tags":{"ai.internal.nodeName":"9a9595bd67c1","ai.operation.id":"0HL6BMO90PHKC","ai.application.ver":"1.0.0.0","ai.operation.name":"OPTIONS Users/AuthenticateUser","ai.internal.sdkVersion":"aspnet5c:2.0.0","ai.cloud.roleInstance":"9a9595bd67c1","ai.location.ip":"172.18.0.5"},"data":{"baseType":"RequestData","baseData":{"ver":2,"id":"HKmnWfByHeU=","name":"OPTIONS Users/AuthenticateUser","duration":"00:00:11.2837000","success":false,"responseCode":"415","url":"http://leo.users/users/authenticate","properties":{"DeveloperMode":"true","httpMethod":"OPTIONS","AspNetCoreEnvironment":"Development"}}}}
I have tried multiple ways to set the headers on the Ionic 2 side. I am not sure what to do/if I am just missing something. Help would be GREATLY appreciated.
Thanks