Assertion failure in -[AFJSONRequestSerializer requestWithMethod:URLString:parameters:error:]

 

AFN 网络请求,报错:Assertion failure in -[AFJSONRequestSerializer requestWithMethod:URLString:parameters:error:]

 

解决办法把请求的url 做如下操作:

 

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

 

 

附加:

stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet] 这个方法是用来进行汉字转码的。

我请求的URL 里面有中文,才会报以上的错误。

当请求的URL中包含空格,文字,或者特殊字符时,不做这个处理,都会报以上错误。

 

posted @ 2019-08-21 15:14  milaliu99  Views(560)  Comments(0)    收藏  举报