Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 请求以错误的编码发送,或者我填写了错误的请求_Java_Angular_Request - Fatal编程技术网

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

Java 请求以错误的编码发送,或者我填写了错误的请求,java,angular,request,Java,Angular,Request,当向服务器发送API请求时,服务器会说“解析HTTP请求头时出错”,尽管我显式地设置了utf-8 angular的请求: import { Injectable } from '@angular/core'; import {HttpClient, HttpHeaders} from '@angular/common/http'; @Injectable({ providedIn: 'root' }) export class MenuHandlerService { constru

当向服务器发送API请求时,服务器会说“解析HTTP请求头时出错”,尽管我显式地设置了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对象将按原样显示


告诉我可能是什么问题?

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

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

请参见