【发布时间】:2020-08-05 10:06:02
【问题描述】:
我正在为此编写一个带有 java 的 angular 项目我已经编写了一个 java rest 服务,我正在使用 post 方法从我的 angular 客户端调用它。它能够调用其余的服务,但它没有来到客户端。
我成功地保持了警报。它没有打印,但在 chrome 网络选项卡中,状态显示为 200。
角度:-
uploadFileToActivity() {
const endpoint = 'http://localhost:8090/sendmails';
let config = {headers: new HttpHeaders({})};
const formData: FormData = new FormData();
formData.append('fileupload', this.fileToUpload);
this.httpClient.post(endpoint, formData).subscribe(data => {
alert();
})
}
Java 服务:-
@PostMapping(value = "/sendmails", headers = "content-type=multipart/*")
public ResponseEntity<String> sendEmails(@RequestParam("fileupload") MultipartFile ExcelDataFile) {
return new ResponseEntity<String>("Success", HttpStatus.OK);
}
我想成功地做一些功能,但调用没有成功。
我在控制台中遇到错误。
error: {error: SyntaxError: Unexpected token S in JSON at position 0 at JSON.parse (<anonymous>) at XMLHtt…, text: "Success"}
headers: HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ}
message: "Http failure during parsing for http://localhost:8090/sendmails"
name: "HttpErrorResponse"
ok: false
status: 200
statusText: "OK"
url: "http://localhost:8090/sendmails"
__proto__: HttpResponseBase
【问题讨论】:
-
你有什么错误吗?
-
@PatrikDendis 我没有收到任何错误
-
您可以尝试在 Java 服务中创建简单的 GET 并从后端获取此信息吗?
-
我可以使用get方法从后端获取数据
-
那么您可以签入例如失败的 Chrome XHR 请求吗?
标签: java angular spring-boot