HTTP status code 0 - Error Domain=NSURLErrorDomain?

后端 未结 12 2292
予麋鹿
予麋鹿 2020-11-27 14:58

I am working on an iOS project.

In this application, I am downloading images from the server.

Problem:

While downloading images I a

12条回答
  •  猫巷女王i
    2020-11-27 15:29

    Sometimes Browser respond to http error handler with Error Object, that have status set to 0, even if you can see 404, 401, 500 etc. error status in network.

    This could happen if your Application and API are on different domains - CORS mechanism is applied. According to CORS for each API request browser sends two requests:

    1. preflight OPTIONS request to understand if API allows Actual/Origin request.
    2. when API allows (OPTIOS request respond with status 204 and correct Access-Control-Allow-Origin headers) - browser send next "Actual/Origin request".

    In Application we are handling Error response for "Actual/Origin request", and if "preflight OPTIONS request" failed - browser doesn't give correct HttpError object for http error handler. So to get correct status of http response - be sure to get success preflight OPTIONS request response.

提交回复
热议问题