Reputation: 508
I call update api for user my parameters is in mixed language. parameters is like this:
{
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";
}
notice MaritalStatus = "Married/\U0935\U093f\U0935\U093e\U0939\U093f\U0924" it is like : "Married/विवाहित"
on postman it works fine but in my code gives error:
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 Code :
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);
} ];
thanks in advance.
Upvotes: 0
Views: 395
Reputation: 531
I think you have Api function issue( because failure error shows "Request failed: internal server error (500)").
You should write this below code in AFHTTPSessionManager failure code(below ->NSLog(@"request failed >>>> :%@",error);)
NSData *data_error = [error.userInfo objectForKey:@"com.alamofire.serialization.response.error.data"];
xmldata = [[NSMutableString alloc] initWithData:data_error encoding:NSASCIIStringEncoding];
xmldata = [[self stringReplaceForDecoding:xmldata] mutableCopy];
NSLog(@"request error %@",error.localizedDescription);
NSLog(@"Api error %@",xmldata);
This will print the actual error in your Api function.
Upvotes: 1
Reputation: 3606
I think the error is in the format of MaritalStatus string
replace it with this in parameter
MaritalStatus = "Married/\u0935\u093f\u0935\u093e\u0939\u093f\u0924"
Upvotes: 1