1. 程式人生 > >用AFN請求網路資料時出錯:(Assertion failure in -[AFHTTPRequestSerializer requestWithMethod:URLString:parameter)

用AFN請求網路資料時出錯:(Assertion failure in -[AFHTTPRequestSerializer requestWithMethod:URLString:parameter)

iOS 開發中使用AFN請求網路資料時出錯:(Assertion failure in -[AFHTTPRequestSerializer requestWithMethod:URLString:parameters:error:])。

原因是AFNetworking請求中含有中文,需要處理urlString的編碼:

urlStr = [urlStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];