尽管请求处理成功,但从发布请求中获取空响应

Arv*_*iya 4 httprequest typescript angular

我正在post使用发出请求httpClient,但null通过请求处理成功获得响应。

serviceClass.ts 文件

this.httpOptions = {
  headers: new HttpHeaders(
    { 
      'Content-Type': 'application/json; charset=utf-8',
      'tenant-code' : 'VdoFWiHL8RFR8fRGNjfZI=',
      'Authorization': 'Basic ' + btoa('pass:username')
    })
}

public Reprocess(ObjProduct) {
var Jobj=JSON.stringify(ObjProduct);
return this._http.post(this.ReprocessUrl,Jobj,this.httpOptions)
}
Run Code Online (Sandbox Code Playgroud)

当我在 Component 中调用上述方法时,我收到了null来自 API 的响应。

组件代码

var op = this.objService.reprocess(this.reprobj);
console.log("output: ", op);
Run Code Online (Sandbox Code Playgroud)

op是完全_scaler=false无法理解的,它正在显示等。如何获得服务呼叫的正确状态?

编辑 1:当我从邮递员那里提出同样的请求时,得到 status Ok 200

编辑 2:下面的代码也给出了null结果(根据@Spart_Fountain 的回答)

var op= this.restApi.Reprocess(this.reprobj).subscribe((data:any) => {
console.log("data "+ data);    
});
Run Code Online (Sandbox Code Playgroud)

邮递员标题截图

在此处输入图片说明

Spa*_*ain 6

调用时得到“奇怪的”响应的原因this.objService.reprocess(this.reprobj);是该方法将返回一个Subscription对象。

详细说明:该方法reprocess返回对 observable 的订阅,因为该方法subscribe()是在return语句本身内部调用的。您宁愿做的是仅返回可观察对象并在reprocess方法之外订阅它:

public reprocess(objProduct) {
  var objParam = JSON.stringify(objProduct);
  return this._http.post(this.url, objParam, this.httpOptions);
}

var op = this.objService.reprocess(this.reprobj).subscribe(resp => {
  console.log("resp from api service: " + resp);
});
Run Code Online (Sandbox Code Playgroud)