[我正在开发一个本机应用程序,并使用Observable.fromPromise进行POST调用,我得到以下响应,但是我不确定如何捕获代码方面的响应,并且我也收到了一些警告] >
响应:
PromiseObservable {_isScalar: false, promise: Promise, scheduler: undefined} promise: Promise _40: 0 _55: Promise _40: 0 _55: Promise _40: 0 _51: 3 _55: Response bodyUsed: true headers: Headers {map: {…}} ok: true status: 200 statusText: undefined type: "default" url: "http://localhost:9999/testPath/pathData" _bodyBlob: Blob {_data: {…}} _bodyInit: Blob {_data: {…}} __proto__: Object _65: 2 _72: null __proto__: Object _65: 3 _72: null __proto__: Object _65: 3 _72: null __proto__: Object scheduler: undefined _isScalar: false __proto__: Observable
警告:
YellowBox.js:67 Possible Unhandled Promise Rejection (id: 0): Response { "_bodyBlob": Blob { "_data": Object { "blobId": "D985543E-CD51-470C-91F9-3407AE59FDA1", "name": "test-data", "offset": 0, "size": 0, "type": "application/json", }, }, "_bodyInit": Blob { "_data": Object { "blobId": "D985543E-CD51-470C-91F9-3407AE59FDA1", "name": "test-data", "offset": 0, "size": 0, "type": "application/json", }, }, "bodyUsed": true, "headers": Headers { "map": Object { "content-type": "application/json; charset=UTF-8", "server": "Jetty(9.2.z-SNAPSHOT)", "transfer-encoding": "Identity", }, }, "ok": true, "status": 200, "statusText": undefined, "type": "default", "url": "http://localhost:9999/testPath/pathData", }
我正在使用mergeMap捕获响应,不确定在这种情况下为什么它不起作用
代码:
const testEpic: Epic<Action, ReduxState> = (
action$: ActionsObservable<any>,
store: MiddlewareAPI<any, ReduxState>,
) =>
action$
.ofType(TEST_GET)
.mergeMap((action) => {
return Observable.merge(
.fetch('/testPath/pathData', payload) // return part which is working properly
.mergeMap((response) => {
// calls not coming here for POST, PUT, DELETE even though it is status 200
})
)
}
)
.catch((error) => {
})
[我正在开发一个本机应用程序,并使用Observable.fromPromise进行POST调用,我得到以下响应,但是我不确定如何用代码和我的方式捕获响应...
尝试一下
fetch("/testPath/pathData", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
我已解决它,实际上是由于contentType不匹配而进入了'错误'