Angular 6 - HttpClient.get 401 error response while trying to read octet stream content

人盡茶涼 提交于 2019-12-11 05:13:32

问题


I am trying to call a rest api that returns octet stream content in Angular 6.

The request is as follows:

fetchOutput(jobId : string,outputId:string) : {

    const options = {
        headers: new HttpHeaders( {
            'Content-Type': 'application/octet-stream',
            'ContentDisposition' : 'attachment',
            'ContentDisposition.FileName' : 'TEST_OUTPUT.csv' } ),
        responseType: 'blob' as 'blob'
      };

    var endpoint = "https://myHost/api/jobs/1/output/2/?oauth_consumer_key=123&oauth_signature_method=HMAC-SHA1&oauth_nonce=651487208&oauth_timestamp=1551696001&oauth_version=1.0&format=csv&oauth_signature=Em12lsCwiEbsj4="

    return this.httpClient.get(endpoint, options);
}

Below is the call to this rest API:

fetchOutput(jobId,outputId).subscribe((data: any) => {

    let b:any = new Blob([data], { type:  "application/octet-stream" });
    console.log(b);
});

Error that I get is:

error:{ Blob
size: 0
type: "text/xml" }

name: "HttpErrorResponse"

ok: false

status: 401

statusText: "Unauthorized"

Also, please note that when I copy the same endpoint and hit on postman, it works perfectly fine. And the same request when fired via ajax also runs successfully.

来源:https://stackoverflow.com/questions/54981779/angular-6-httpclient-get-401-error-response-while-trying-to-read-octet-stream

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!