请求以错误的编码发送,或者我错误地填写了请求

hfwmuf9z  于 2021-07-08  发布在  Java
关注(0)|答案(1)|浏览(334)

当向服务器发送api请求时,服务器会说“error parsing http request header”,尽管我显式地设置了utf-8
来自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();
  }
}

java spring服务器出错

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]

git后端和前端的源代码
当通过浏览器访问api时,json对象将按原样显示
告诉我有什么问题?

guicsvcw

guicsvcw1#

这意味着服务器不支持https,请尝试以下操作:

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

https->http

相关问题