Readdy Write  
0,00 €
Your View Money
Views: Count
Self 20% 0
Your Content 60% 0

Users by Links 0
u1*(Content+Views) 10% 0
Follow-Follower 0
s2*(Income) 5% 0

Count
Followers 0
Login Register as User

Solved: Angular Error TypeError: Failed to execute setRequestHeader on XMLHttpRequest: String contains non ISO-8859-1 code point

14.02.2023 (👁3738)

Solved: Angular Error TypeError: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': String contains non ISO-8859-1 code point

: TypeError: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': String contains non ISO-8859-1 code point. at http://localhost:4200/vendor.js:19785:49 at

 

Lösung:
über den Interceptor wird ein Token in jede URL Abfrage eingefügt. Dieser Token enthält Sonderzeichen und dient normalerweise der Authorization (verschlüsselte User Berechtigung)

Ein Bild, das Text, Screenshot, Computer, drinnen enthält.

Automatisch generierte Beschreibung

 

 

Der Interceptor Code fügt bei Angular Beispielen immer einen JWT Bearer Token ein, wenn es zu einen Authorization Fehler 401 kommt.

Dieser Code ist aus einem Internet Example… und somit fehlerhaft

Problem: Interceptor Code

import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from "@angular/common/http";

import { Injectable } from "@angular/core";

import { Observable } from "rxjs";

import { CookieService } from 'ngx-cookie-service'  //*for using cookies

 

@Injectable()

export class AuthenticationInterceptor implements HttpInterceptor{

    //</ init >

    constructor(private cookieService: CookieService) { }

    //</ init >

 

    //* on any authorize-error 401, add the token to the header

    intercept(

        req: HttpRequest<any>,

        next: HttpHandler): Observable<HttpEvent<any>> {

        var token=this.cookieService.get("t");

        if (token){

            req=req.clone({

                setHeaders:{Authorization: `Bearer ${token}` },   //*token contains userid internal,encrypted

            });

        }

 

        return next.handle(req);

    }

 

}