C# 将字节数组内容加载到角度2中的浏览器

C# 将字节数组内容加载到角度2中的浏览器,c#,asp.net,angular,C#,Asp.net,Angular,我正在使用ASP.NETWebAPI进行Angular 4项目,并尝试以PDF格式在浏览器中加载字节数组内容。我正在从ASP.NETWebAPI返回一个包含字节数组的HttpResponseMessage,但在客户端没有得到响应。这是我的密码-- 服务器端(C#) var response=新的HttpResponseMessage(); var流=新的内存流(offerleterpdfbyte); //OfferleterPdfByte是动态创建的pdf文档的字节数组 response.Sta

我正在使用ASP.NETWebAPI进行Angular 4项目,并尝试以PDF格式在浏览器中加载字节数组内容。我正在从ASP.NETWebAPI返回一个包含字节数组的HttpResponseMessage,但在客户端没有得到响应。这是我的密码--

服务器端(C#)
var response=新的HttpResponseMessage();
var流=新的内存流(offerleterpdfbyte);
//OfferleterPdfByte是动态创建的pdf文档的字节数组
response.StatusCode=HttpStatusCode.OK;
response.Content=newbytearray内容(stream.ToArray());
组件中的角度代码
公开预览Wofferletter(){
const editorContentHtml=this.frmReviewOfferLetter.controls[“EditorNote”].value;
此.\u humanResourceService.PreviewCandidateOfferLetter(editorContentHtml).订阅(
数据=>{
const file=new Blob([data],{type:“application/pdf”});
const fileUrl=URL.createObjectURL(文件);
window.open(fileUrl);
},
错误=>{
console.log(错误);
},
() => {
});
}
//使用中的方法
公共预览CandidateOfferletter(OfferleterHTML:any):可观察{
返回此信息。httpHelperService.ExecutePostRequest(apirlconfig.HumanResource.previewcandidateOfferleter,OfferleterHTML);
}
服务器端方法是HttpPost类型,并且执行得非常好。在调试服务器代码时,我能够看到字节数组,但是响应不会到达组件中的数据部分,它总是到达错误部分,错误对象如下--

error=Object{StatusCode:undefined,Message:undefined}
//服务代码
public ExecutePostRequest(端点:any,参数?:any,customErrorCallback?:any):可观察{
这是。_requestOptions=新的requestOptions({
方法:RequestMethod.Post,
url:this.baseUrl+端点,
headers:this.headers,
正文:JSON.stringify(params),
证书:正确
});
this.loggerService.Log(“信息”,“执行请求:+this.baseUrl+端点,null”,“HttpHelperService”,“executeRequest”,参数);
返回此.u http.request(新请求(此.u requestOptions)).map(此.ExtractData).catch(customErrorCallback!==未定义?customErrorCallback:this.HandleError);
}

请告诉我我做错了什么。提前谢谢。

您能分享一下您的服务吗code@Chellappan-我编辑了这个问题。请查看那里的服务代码。在控制台上,您得到了什么错误?@Chellappan-{状态:未定义,消息:未定义}
Server side (C#)    
var response = new HttpResponseMessage();
var stream = new MemoryStream(offerLetterPdfByte);
//offerLetterPdfByte is the byte array of a dynamically created pdf document
response.StatusCode = HttpStatusCode.OK;
response.Content = new ByteArrayContent(stream.ToArray());

Angular Code in Component
public PreviewOfferLetter() {
    const editorContentHtml = this.frmReviewOfferLetter.controls["EditorNote"].value;
    this._humanResourceService.PreviewCandidateOfferLetter(editorContentHtml).subscribe(
      data => {
        const file = new Blob([data], {type: "application/pdf"});
        const fileUrl = URL.createObjectURL(file);
        window.open(fileUrl);
      },
      error => {
        console.log(error);
      },
      () => {

      });
  }

//Method In Service
public PreviewCandidateOfferLetter(offerLetterHtml: any): Observable<any>{
    return this._httpHelperService.ExecutePostRequest(ApiUrlConfig.HumanResource.PreviewCandidateOfferLetter, offerLetterHtml);
  }
 error = Object {StatusCode: undefined, Message: undefined}

//Service Code
public ExecutePostRequest(endpoint: any, params?: any, customErrorCallback?: any): Observable<any> {
      this._requestOptions = new RequestOptions({
          method: RequestMethod.Post,
          url: this.baseUrl + endpoint,
          headers: this.headers,
          body: JSON.stringify(params),
          withCredentials: true
      });
      this._loggerService.Log("info", "Execute Request : " + this.baseUrl + endpoint, null, "HttpHelperService", "executeRequest", params);
      return this._http.request(new Request(this._requestOptions)).map(this.ExtractData).catch(customErrorCallback !== undefined ? customErrorCallback : this.HandleError);
    }