-1103 Error Domain=NSURLErrorDomain Code=-1103 "resource exceeds maximum size" iOS 13

IosObjective CSwiftIos13

Ios Problem Overview


We are facing the following networking error when the response is somehow large(14kb) on iOS 13.

[-1103] Error Domain=NSURLErrorDomain Code=-1103 "resource exceeds maximum size"

As we are using Alamofire, this problem is treated as error result which breaks our treatments of the results.

The strange thing is that if we use NSURLSession directly, though this error is still seen from logging, we don't actually receive it in the callback of

session.dataTask(with: request) { value, response, error in ... }

So the result can treated correctly.

This problem is never seen before. Anyone has got some idea on that ?

Ios Solutions


Solution 1 - Ios

With the help of the Slack community, we find the answer is that on iOS13, it is not allowed to add a body in GET request. To make it work again, we can either switch to a POST/PUT request or add body value via url parameters of the GET request.

Solution 2 - Ios

Pass query parameters in GET request like the following:

let parameters: Parameters = [    "param": value]
Alamofire.request(urlString, method: .get, parameters: parameters, encoding: URLEncoding.queryString)

Solution 3 - Ios

I have face same issue and find out the solution.

You can't pass parameter in body while using GET.

Either use POST method if API support or pass it in URL like below.

> AnyURL?Parameter=Value&Parameter=Value

Solution 4 - Ios

Finally found the answer. For GET services I was trying to add an httpBody. Something like this:

do {
    request.httpBody = try JSONSerialization.data(withJSONObject: parameters, options: .prettyPrinted)
} catch let error {
    errorCompletion(error)
    return
}

The solution was just to add an if to avoid that chunk of code if httpMethod is a GET. Seems like an iOS 13 new behavior and the error message given by Swift definitely not helps at all

Solution 5 - Ios

Alamofire: You should try this!

Alamofire.request(urlString, method: .get, parameters: parameters, encoding: URLEncoding.queryString)

Just avoid the httpBody for the GET API request.

if requestType != .get{
     request.httpBody = data
}

#OR

For GET request append parameter into URL instead of the HTTP body

Use the below extension to create a query parameter from the dictionary.

extension NSObject {
    func buildQueryString(fromDictionary parameters: [String:String]) -> String {
        var urlVars = [String]()
        for (var k, var v) in parameters {
            let characters = (CharacterSet.urlQueryAllowed as NSCharacterSet).mutableCopy() as! NSMutableCharacterSet
            characters.removeCharacters(in: "&")
            v = v.addingPercentEncoding(withAllowedCharacters: characters as CharacterSet)!
            k = k.addingPercentEncoding(withAllowedCharacters: characters as CharacterSet)!
            urlVars += [k + "=" + "\(v)"]
        }
        
        return (!urlVars.isEmpty ? "?" : "") + urlVars.joined(separator: "&")
    }
}

Solution 6 - Ios

I used default url encoding instead of default json encoding and it's worked for me.

Alamofire.request(url, method: .get, parameters: param, encoding: URLEncoding.default)

OR

If you using URLRequestConvertible

enum NetworkRouter: URLRequestConvertible {
    
    case someCase(lang:String)
    
    var method: HTTPMethod {
        return .get
    }
    
    var parameters: Parameters? {
        switch self {
        case .someCase(let param):
            return ["lang": param.lang]
        default:
            return nil
        }
    }
    
    var url: URL {
        switch self {
        case .someCase(let param):
            return URL(string: Constants.baseURL + Constants.endPoint)!
        default:
            return URL(string: Constants.baseURL)!
        }
    }

    var encoding: ParameterEncoding {
        return URLEncoding.default
    }
    
    func asURLRequest() throws -> URLRequest {
        var urlRequest = URLRequest(url: url)
        urlRequest.httpMethod = method.rawValue
        return try encoding.encode(urlRequest, with: parameters)
    }
}

Solution 7 - Ios

I got that issue because i pass empty parameters in Alamofire when send get request. So, instead of sending empty parameters i simply replace it for nil.

Solution 8 - Ios

My fix is I only set .parameters to nil, then everything works fine. Because in Swift it still initialize the value of .parameters.

self.request.parameters = nil

Solution 9 - Ios

Here you might have missing the method of the URL request that you are passing to data task. You have to add POST/PUT/DELETE to the URL request method parameter like below.

var request: URLRequest = URLRequest(url: SOME_VALID_URL) 
request.body = SOME_VALID_DATA_IN_BYTES
request.method = "post" --> You are missing this.

Solution 10 - Ios

I only see this issue when I build with Xcode 11. If I revert back to Xcode 10.3 I do not have the same issue anymore. While not a forever fix, if you're needing to push out code you can revert until you have time to fix it.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJibeexView Question on Stackoverflow
Solution 1 - IosJibeexView Answer on Stackoverflow
Solution 2 - IossmartwolfView Answer on Stackoverflow
Solution 3 - IosHardik VyasView Answer on Stackoverflow
Solution 4 - Iosuser3175133View Answer on Stackoverflow
Solution 5 - IosHitesh SuraniView Answer on Stackoverflow
Solution 6 - IosYasir RomayaView Answer on Stackoverflow
Solution 7 - IosEvgeniy KlebanView Answer on Stackoverflow
Solution 8 - IosAika Melanie DionisioView Answer on Stackoverflow
Solution 9 - IosGavara.SuneelView Answer on Stackoverflow
Solution 10 - IosWillView Answer on Stackoverflow