更新我在一臺服務器上放置了兩個項目,它們是客戶端和服務器 RestAPI 應用程序。我將 4200 設置為客戶端的端口(由 Angular 6 編寫)和服務器端 WebSrv 的端口 8990。我使用命令運行 Spring one java -jar artifact.jar,它工作正常并響應任何請求。但是對于客戶端,當我從本地機器使用 IP 運行它時:localhost:4200(使用 IntellijIdea 內置構建器或使用 Angular CLI)它工作正常并且可以發(fā)送請求并接收響應。但是,當我從該服務器(WebSrv 服務器所在的位置)運行它并運行時,它正確顯示了第一個 html 頁面,但是當我單擊發(fā)送請求的按鈕時,沒有任何反應(也沒有異?;蛉魏稳罩荆┎⑶曳掌鞑皇墙邮苋魏我螅?!我已經搜索了我的問題,但沒有任何幫助。如果有人能幫助我找到解決方案,我將不勝感激。我想知道是否有人知道是什么問題。這是我的客戶端代碼(Angular)import {Component, NgModule, OnInit} from '@angular/core';import {HttpClient, HttpHeaders} from '@angular/common/http';import {RouterModule, Router} from '@angular/router';// const URL = 'http://localhost:8990/getUserId';const URL = 'http://getuserid.mycompany.com:8990/getUserId';@Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css']})export class AppComponent { constructor( private http: HttpClient ) { } fileToUpload: File = null; id: String = '0'; inputId(event) { this.id = event.target.value; console.log('id is -- > ' + event.target.value); } inputFile(event) { this.fileToUpload = event.target.files[0]; console.log('File path -- > ' + event.target.files[0].name); } onSubmit(id: string, file: File) { const frmData = new FormData(); console.log('POST'); // @ts-ignore frmData.append('id', this.id); frmData.append('inputPackage', this.fileToUpload); console.log('id --> ' + this.id); console.log('File name --> ' + this.fileToUpload.name); this.http.post(URL, frmData).subscribe(res => { const resp = JSON.parse(JSON.stringify(res)); if (resp['user'] != null) { if (resp['user']['user-id'] === false) { alert('Successful!! Your User ID is : ' + resp['user']['user-id']); } else { alert('Sorry!! Error occurred : ' + resp['error-message']); } } else { alert('Sorry!! Error occurred : ' + resp['error-message'] ); } }); }}
添加回答
舉報
0/150
提交
取消