我尝试使用HttpClient
发送文件:
public async uploadProfile(data: UploadProfile): Promise<any> {
return await this.http.post(this.uploadProfileUrl, data).toPromise();
}
在发送文件之前,我将其准备为二进制数组:
interface UploadProfile {
file: any;
}
file = [123, 10, 32, 32, 34, 100, 105, 115, 97, 98, 108, 101, 83, 105, 122, 101, 76, 105, 109]
但是我得到错误:
TypeError: Cannot read property 'toLowerCase' of undefined
at HttpXsrfInterceptor.intercept (http.js:2177)
这可能是由于您在请求期间未定义URL。尝试做以下测试:
更改:
public async uploadProfile(data: UploadProfile): Promise<any> {
return await this.http.post(this.uploadProfileUrl, data).toPromise();
}
收件人:
public async uploadProfile(data: UploadProfile): Promise<any> {
return await this.http.post('http://yourUrl/resource', data).toPromise();
}
如果这可行,并且您再也看不到错误,请尝试找出为什么在拨打电话时未定义uploadProfileUrl
。