0

I am trying to post some data and I am passing an access token as query string. I will be getting a blob response from server. I used following code :

public issueId(asset: Type): Observable<Blob> {
    let urlSearchParams = new HttpParams().set('access_token', this.cookieService.get('access_token'));
    console.log('Entered DataService issueID');
    return this.httpClient.post('http://localhost:3000/api/system/identities/issue', asset, {urlSearchParams},{responseType: "blob"});
}

I am getting error "Expected 2-3 arguments, but got 4". I am using angular 4. Asset is the body of post request.

4
  • It's basically you are passing more arguments than expected Commented Apr 17, 2018 at 10:21
  • ya , but I then how I can reduce the arguments. I need to mention api address, the body, the responsetype and query string as well. Is there any other way to do it ? Commented Apr 17, 2018 at 10:23
  • You can remove the {responseType: "blob"} and handle it once you got the response Commented Apr 17, 2018 at 10:24
  • I just added the query string in the api address, now there is no need of param argument. Commented Apr 17, 2018 at 10:53

2 Answers 2

1

As per the post documentation , you have to do as below

put(url: url, body: data, 
 options: {params: urlSearchParams,responseType: "blob"});

aso you need to pass responsetype ans params as part of options

Sign up to request clarification or add additional context in comments.

Comments

0

You are sending multiple optional objects with request. Change your request like this.

public issueId(asset: Type): Observable<Blob> {
    let urlSearchParams = new HttpParams().set('access_token', this.cookieService.get('access_token'));
    console.log('Entered DataService issueID');
    return this.httpClient.post('http://localhost:3000/api/system/identities/issue', asset, { params: urlSearchParams, responseType: "blob"});
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.