我正在使用Angular http模块v4.4.6.当Angular应用程序(客户端)向HttpClient服务器发送PUT请求(使用),并且服务器响应状态200(OK)而没有正文中的任何数据时,角度http模块抛出一个HttpErrorResponse.
这是一个正确的功能还是一个错误?
如何在没有任何数据的情况下处理PUT响应?
详细地:
在最近的版本中,我使用了普通Http模块,它的方法是put().在那里,我需要调用res.json()以获取正文中的JSON数据.put()方法返回Observable<Response>.
现在我使用更新的HttpClient和它的put()方法.此方法返回Observable<Object>.似乎该json()方法在内部调用并导致我看到的错误.
'Content-Type': 'application/json'.这导致HTTP PUT请求标头Accept:application/json, text/plain, */*).
HttpErrorResponse {headers: HttpHeaders, status: 200, ...
error:
error: SyntaxError: Unexpected end of JSON input at ..
text: ""
headers: HttpHeaders {normalizedNames: Map(0), lazyUpdate: ...
message: "Http failure during parsing for ...
name: "HttpErrorResponse"
ok: false
status: 200
statusText: "OK"
url: ...
@yonexbat,谢谢你是对的.
如果使用....
const response = this.http.put(url, data, { responseType: 'text'}).toPromise();
Run Code Online (Sandbox Code Playgroud)
... 问题已经解决了.
| 归档时间: |
|
| 查看次数: |
7235 次 |
| 最近记录: |