AFHTTPRequestOperationManager*manger=[AFHTTPRequestOperationManager manager];
NSDictionary*dic=[[NSDictionary alloc]initWithObjectsAndKeys:_phonenumber.text,@"phonenumber",_passWord.text,@"password",@"asd",@"username", nil];
manger.responseSerializer=[AFJSONResponseSerializer serializer]
;
manger.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
NSDictionary*dd=[[NSDictionary alloc]initWithObjectsAndKeys:dic ,@"user", nil];
NSData*data=[NSJSONSerialization dataWithJSONObject:dd options:NSJSONWritingPrettyPrinted error:nil];
NSString*url=@"http://192.168.2.121:8080/phonebook/regist.do";
[manger.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[manger POST:url parameters:(NSData*)data success:^(AFHTTPRequestOperation *operation, id responseObject){
NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error){
NSLog(@"%@",error);
}
];
代码如上
报错如下 哪位大神知道告诉下小弟
2015-07-06 19:16:42.287 PhoneBook[8541:489588] Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x7f9332f27e20 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set., NSUnderlyingError=0x7f9332d38880 "Request failed: bad request (400)"}
NSDictionary*dic=[[NSDictionary alloc]initWithObjectsAndKeys:_phonenumber.text,@"phonenumber",_passWord.text,@"password",@"asd",@"username", nil];
manger.responseSerializer=[AFJSONResponseSerializer serializer]
;
manger.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
NSDictionary*dd=[[NSDictionary alloc]initWithObjectsAndKeys:dic ,@"user", nil];
NSData*data=[NSJSONSerialization dataWithJSONObject:dd options:NSJSONWritingPrettyPrinted error:nil];
NSString*url=@"http://192.168.2.121:8080/phonebook/regist.do";
[manger.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[manger POST:url parameters:(NSData*)data success:^(AFHTTPRequestOperation *operation, id responseObject){
NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error){
NSLog(@"%@",error);
}
];
代码如上
报错如下 哪位大神知道告诉下小弟
2015-07-06 19:16:42.287 PhoneBook[8541:489588] Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x7f9332f27e20 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set., NSUnderlyingError=0x7f9332d38880 "Request failed: bad request (400)"}
manager.requestSerializer=[AFHTTPRequestSerializer serializer];
manager.responseSerializer=[AFHTTPResponseSerializer serializer];这样应该能旧居问题了,如果还是解决不了,那肯定是后台的问题。