Ionic 2 cannot send messages to asp dotnet core even with CORS enabled
I tried to find an answer, some are close, but not what I'm looking for.
This is my problem, I am developing an Ionic app and am currently viewing the view in a web browser. I am unable to post any content back to my main dotnet asp server.
My stack looks like this: Front-End
- Ionic 2 - Latest version using latest Angular 4
- Nginx - as my proxy
- Docker - how my container works with dotnet core apps
Here is the code for the post I'm 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 support 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");
In the Visual Studio 2017 output window, I see the response 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 tried several ways to set headers on the Ionic 2 side. I'm not sure what to do / if I just missed something. Help would be much appreciated.
thank
+3
source to share