美文网首页
http请求url参数包含+号,被解析为空格

http请求url参数包含+号,被解析为空格

作者: zy_Judy | 来源:发表于2020-11-20 17:10 被阅读0次

    https://github.com/angular/angular/issues/11058

    @Injectable()
    export class EncodeUrlParamsSafelyInterceptor implements HttpInterceptor, HttpParameterCodec {
      intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
        const newParams = new HttpParams({
          fromString: req.params.toString(),
          encoder: this,
        });
    
        return next.handle(req.clone({
          params: newParams,
        }));
      }
    
      encodeKey(key: string): string {
        return encodeURIComponent(key);
      }
    
      encodeValue(value: string): string {
        return encodeURIComponent(value);
      }
    
      decodeKey(key: string): string {
        return decodeURIComponent(key);
      }
    
      decodeValue(value: string): string {
        return decodeURIComponent(value);
      }
    }
    

    相关文章

      网友评论

          本文标题:http请求url参数包含+号,被解析为空格

          本文链接:https://www.haomeiwen.com/subject/taxjiktx.html