ios - 使用 AFNetworking 的 API 请求出错

标签 ios objective-c iphone afnetworking

我为用户调用更新 api 我的参数是混合语言。参数是这样的:

{
    Address = "Judd ";
    AnnualIncome = 0;
    AreYouManglik = NO;
    AreYouPhysicallyChallenged = NO;
    MaritalStatus = "Married/\U0935\U093f\U0935\U093e\U0939\U093f\U0924";
    Mobile = 8441960471;
    MotherGotra = "Not Available";
    MotherProfession = "Not Available";

}

注意 MaritalStatus = "Married/\U0935\U093f\U0935\U093e\U0939\U093f\U0924"它就像:"Married/विवाहित"

在 postman 上它工作正常但在我的代码中给出错误:

request failed >>>>  :Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0." UserInfo={NSDebugDescription=Invalid value around character 0., NSUnderlyingError=0x60000045b630 {Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: internal server error (500)" UserInfo=

{com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x60800063c300> { URL: http://bagrasamaaj.com/myapp/api/updateprofile } { status code: 500, headers {
    "Cache-Control" = "no-cache, private";
    Connection = close;
    "Content-Encoding" = gzip;
    "Content-Type" = "text/html; charset=UTF-8";
    Date = "Tue, 08 Aug 2017 03:11:00 GMT";
    Server = Apache;
    "Transfer-Encoding" = Identity;
    Vary = "Accept-Encoding,User-Agent";
    "X-Powered-By" = "PHP/5.6.30";
    "X-RateLimit-Limit" = 60;
    "X-RateLimit-Remaining" = 59;
} }, NSErrorFailingURLKey=http://bagrasamaaj.com/myapp/api/updateprofile, com.alamofire.serialization.response.error.data=<3c21444f 43545950 45206874 6d6c3e0a 3c68746d 6c3e0a20 2020203c 68656164 3e0a2020 20202020 20203c6d 65746120 63686172 7365743d 22555446 2d382220 2f3e0a20 20202020 2020203c 6d657461 206e616d 653d2272 6f626f74 73222063 6f6e7465 6e743d22 6e6f696e 6465782c 6e6f666f 6c6c6f77 22202f3e 0a202020 20202020 203c7374 796c653e 20202020 20202020 20202020 626f6479 207b2062 61636b67 726f756e 642d636f 6c6f723a 20234639 46394639 3b20636f 6c6f723a 20233232 323b2066 6f6e743a 20313470 782f312e 34204865 6c766574 6963612c 20417269 616c2c20 73616e73 2d736572 69663b20 6d617267 696e3a20 303b2070 61646469 6e672d62 6f74746f 6d3a2034 3570783b 207d0a0a 20202020 20202020 20202020 61207b20 63757273 6f723a20 706f696e 7465723b 20746578 742d6465 636f7261 74696f6e 3a206e6f 6e653b20 7d0a2020 20202020 20202020 2020613a 686f7665 72207b20 74657874 2d646563 6f726174 696f6e3a 20756e64 65726c69 6e653b20 7d0a2020 20202020 20202020 20206162 62725b74 69746c65 5d207b20 626f7264 65722d62 6f74746f 6d3a206e 6f6e653b 20637572 736f723a 2068656c 703b2074 6578742d 6465636f 72617469 6f6e3a20 6e6f6e65 3b207d0a 0a202020 20202020 20202020 20636f64 652c2070 7265207b 20666f6e 743a2031 3370782f 312e3520 436f6e73 6 ......

API 代码:

  AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    AFJSONResponseSerializer *responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingAllowFragments];
    manager.responseSerializer = responseSerializer;

    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"application/json", nil];

    NSLog(@"dict update %@",dict);

    NSString*url = [NSString stringWithFormat:@"%@updateprofile",baseUrl];

    [manager POST:url parameters:dict constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {

        if(profilePic !=nil){
            NSData *imageData = UIImageJPEGRepresentation(profilePic, 1.0);

            [formData appendPartWithFileData:imageData name:@"image" fileName:@"image" mimeType:@"image/jpeg"];
        }

    } progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {

        NSLog(@"response update: %@",responseObject);
        [delegate passRequestedArray:responseObject WithId:@"update"];


    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

        NSLog(@"request failed >>>>  :%@",error);

    } ];

提前致谢。

最佳答案

我认为错误是 MaritalStatus 字符串的格式

在参数中用这个替换它

MaritalStatus = "Married/\u0935\u093f\u0935\u093e\u0939\u093f\u0924"

关于ios - 使用 AFNetworking 的 API 请求出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45558803/

相关文章:

ios - 点击按钮时折叠表格行

ios - 如何在 Swift 中对字典类型的数组应用 removeAtIndex?

ios - UIView 和 subview 委托(delegate)

ios - 如何从一个 Containerview 传递到另一个 UIViewController

iphone - 使用 Core Data 实现枚举的最佳方法

iphone - libFlurryAnalytics.a错误

ios - 如何知道 UIPanGestureRecognizer 是否来自一个显示边缘?

ios - Firebase 远程配置设置默认值 : doesn't store NSDictionary

iphone - 将日期插入 SQLite

iphone - 使用AWS iOS SDK从cloudfront发行版获取文件