How to post a string in the body of a post request with Angular 4.3 HttpClient?

前端 未结 3 1728
小蘑菇
小蘑菇 2021-01-04 02:24

We\'ve got a .net WebAPI which looks for a filepath string in the body of a post request and returns the corresponding image. I\'m struggling to successfully pass a string t

3条回答
  •  情话喂你
    2021-01-04 02:48

    I just tried another altrnative way by this options and directing posting String path Json to body of post method.

     getImage(path: string) {
                let headers = new Headers({ 'Content-Type': 'application/json' });
                let options = new RequestOptions({ headers: headers });
    
                return new Promise((resolve, reject) => {
                    this.http.post('${apiUrl}',path, options)
                    .map((res) => res.json()).share()
                    .subscribe(res => {
                      resolve(res)
                    }, (err) => {
                      reject(err);
                    });
                });
              }
    

    I would be happy if it works.Thanks

提交回复
热议问题