0

when sending an API request to the server, the server says "Error parsing HTTP request header", although I explicitly set utf-8

request from angular:

import { Injectable } from '@angular/core';
import {HttpClient, HttpHeaders} from '@angular/common/http';

@Injectable({
  providedIn: 'root'
})
export class MenuHandlerService {

  constructor(private httpClient: HttpClient) {
    this.fillContent('Main');
  }

  // tslint:disable-next-line:typedef
  fillContent(category: string){
    console.log(category);
    this.getDataFromServer(category).
    then(res => {
    console.log('res: ', res);
    });
  }

  // tslint:disable-next-line:typedef
  getDataFromServer(category: string) {
    const headers = new HttpHeaders({'Content-Type':'application/json; charset=utf-8'});
    const url = 'https://localhost:8080/api/v1/lessons';
    // @ts-ignore
    return this.httpClient.get(url, headers).toPromise();
  }
}

error on the java spring server

2020-11-16 18:49:43.616  INFO 11212 --- [nio-8080-exec-1] o.apache.coyote.http11.Http11Processor   : Error parsing HTTP request header
 Note: further occurrences of HTTP request parsing errors will be logged at DEBUG level.

java.lang.IllegalArgumentException: Invalid character found in method name [0x160x030x010x020x000x010x000x010xfc0x030x030x8e0x1f0xbdMjM0x0dA0xe60x170xdb0xb50xf40x7f0xd50x0f0x030x9a0x06O0x80y:40xa8d*0x1f0xc20x03Z0x99]. HTTP method names must be tokens
    at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:413) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:261) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) ~[na:na]
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630) ~[na:na]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
    at java.base/java.lang.Thread.run(Thread.java:832) ~[na:na]

source on git BackEnd and FrontEnd

when visiting the API through the browser the JSON object is displayed as it should be

tell me what could be the problem?

Nez
  • 3
  • 1
  • see https://stackoverflow.com/questions/45286764/adding-a-http-header-to-the-angular-httpclient-doesnt-send-the-header-why – Happy Coder Nov 16 '20 at 16:43

1 Answers1

1

It means server does not support HTTPS, so try this:

const url = 'http://localhost:8080/api/v1/lessons';

https -> http