Subject says it all. We want to make a URLRequest
where all we care about is the HTTP return code (e.g. 200, 400, etc.) which we can get from the httpUrlResponse
object. What we don't need is a response body, since there isn't one.
Here's how you make a request that expects a response body...
let urlRequest = [insert code to make request]
let urlSession = [insert code to make session]
let task = urlSession.dataTask(with: urlRequest) {
(responseBodyData, httpUrlResponse, error) in
if let error = error {
// handle error
return
}
guard let responseBodyData = responseBodyData else {
// Handle missing data
return
}
}
task.resume()
But how do you do it if you don't want/need responseBodyData
? Or do you just use the same code, ignoring the responseBodyData
field, replacing it with _
since it is optional and can be ignored?