Code: Select all
OPTIONS http://localhost:9090/api/values 401 (Unauthorized)
Failed to load http://localhost:9090/api/values: Response for preflight has invalid HTTP status code 401.
< /code>
Ich habe alle Mittel zur Implementierung von CORs mit microsoft.aspnet.webapi.cors < /code> ohne Erfolg ausprobiert. Derzeit habe ich das Paket von microsoft.aspnet.webapi.cors
Web.config: < /strong> < /p>
Code: Select all
< /code>
.net Web API 'VALUTSCONTROLLER.CS': < /strong> < /p>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
namespace api.Controllers
{
[Authorize]
public class ValuesController : ApiController
{
// GET api/values
public IEnumerable Get()
{
return new string[] { "value1", "value2" };
}
// GET api/values/5
public string Get(int id)
{
return "value";
}
// POST api/values
public void Post([FromBody]string value)
{
}
// PUT api/values/5
public void Put(int id, [FromBody]string value)
{
}
// DELETE api/values/5
public void Delete(int id)
{
}
}
}
< /code>
Winkelkomponente (sendet Daten an meinen Winkeldienst): < /strong> < /p>
constructor(private myService: MyService) {
this.myService.myPost({ID: 1, FirstName: 'Bob'})
.subscribe(
data => console.warn(data),
err => console.error(err),
() => console.log("empty")
);
}
< /code>
Winkeldienst (veröffentlicht die Daten der Komponente an meine Web -API < /code>): < /strong> < /p>
import { Injectable } from '@angular/core';
import { HttpClient, HttpResponse, HttpRequest, HttpHeaders, HttpInterceptor, HttpHandler, HttpEvent, HttpParams} from '@angular/common/http';
import { Observable } from 'rxjs';
import { from } from 'rxjs';
import { map, filter, catchError, mergeMap } from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
export class MyService {
constructor(private http: HttpClient) {
};
public myPost(body) {
const httpOptions = {
withCredentials: true
}
return this.http.post("http://localhost:9090/api/values", body, httpOptions);
}
}
MyService.ts[/b]
public myPost(body) {
const httpOptions = {
headers: new HttpHeaders({
'Authorization': '?????'
}),
withCredentials: true
}
return this.http.post("http://localhost:9090/api/values", body, httpOptions);
}
< /code>
Vielleicht ist dies jedoch nicht einmal mein Problem. CORS + Windows -Authentifizierung - irgendwelche Ideen?