Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.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
body.set Angular2将文件发布到第三方_Angular - Fatal编程技术网

body.set Angular2将文件发布到第三方

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

我需要发布一个小文件到第三方服务器。我已经发布了他们所需的字段,而且效果很好,但是我不知道如何使用body.set设置文件

这是我在.ts上的代码:

    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};