Any way to get the response body during HTTP errors?

前端 未结 2 1649
谎友^
谎友^ 2020-12-13 23:36

I\'m hitting an API that will occasionally throw a HTTP 403 error, and the response body can give some extra information in the form of json, however for the life of me I ca

2条回答
  •  醉酒成梦
    2020-12-14 00:14

    Swift 5 to get body response easily in DefaultDataResponse extension :

    String(data: data!, encoding: String.Encoding.utf8)
    

提交回复
热议问题