body.set Angular2将文件发布到第三方
我需要发布一个小文件到第三方服务器。我已经发布了他们所需的字段,而且效果很好,但是我不知道如何使用body.set设置文件 这是我在.ts上的代码:body.set Angular2将文件发布到第三方,angular,Angular,我需要发布一个小文件到第三方服务器。我已经发布了他们所需的字段,而且效果很好,但是我不知道如何使用body.set设置文件 这是我在.ts上的代码: var APIURL = sessionStorage.getItem('endpoint') + "/setattributes"; let options = { headers: new HttpHeaders().set('Content-Type', 'application/x-www-for
var APIURL = sessionStorage.getItem('endpoint') + "/setattributes";
let options = { headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded') };
let body = new URLSearchParams();
body.set('id', this.id);
body.set('session', encodeURIComponent(sessionStorage.getItem('session')));
body.set('token', encodeURIComponent(sessionStorage.getItem('token')));
body.set('channel', encodeURIComponent(channel));
this.httpClient.post(APIURL, body.toString(), options).subscribe(
result => { .....
这是我的HTML
<input type='file' (change)="onSelectFile($event)" class="NiceUpload" id="file" accept=".log">
他们说我需要将文件发布为Im发布其余字段,并将其称为“日志文件”,但body.set不起作用
有什么建议吗
谢谢 建议在选项变量中添加一个值 证书:正确
let options = { headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded'), withCredentials: true};