AFHTTPRequestOperationManager* manager = [AFHTTPRequestOperationManager manager];
NSLog(@"%@",[urlOfVm class]);
NSMutableString *url = [NSMutableString stringWithString:urlOfVm];
[url appendString:in];
NSLog(@"%@",url);
NSURLRequest* request = [[AFJSONRequestSerializer serializer]requestWithMethod:@"POST" URLString:url parameters:diccp ];
AFHTTPRequestOperation* operation = [manager HTTPRequestOperationWithRequest:request
success:^(AFHTTPRequestOperation *operation, id responseObject) {
if (responseObject != nil) {
NSLog(@"----------------------response:%@",[operation responseString]);
NSLog(@"responseObject:%@",responseObject);
[self create:(NSDictionary *)responseObject];
}
else{
NSLog(@"return null");
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"response:%@",[error description]);
}];
[operation setResponseSerializer:[AFJSONResponseSerializer serializer] ];
[[NSOperationQueue mainQueue] addOperations:@[operation] waitUntilFinished:NO];
下面是java接口:
/**
* user register
* if the method return 0 ,it means the user exists; return 1:it means register success, return 2 means the internet has some problem
*
* @param parameter
* @return
*/
@RequestMapping(value = "/register")
@ResponseBody
public String registerAccount(@RequestBody Account account) {
System.out.println(account.getUserName());
Account account1 = accountManager.isExistAccountByUserName(account
.getUserName());
if (null != account1) {
return "0";
} else {
try {
account.setGenerateTime(DateUtils.formatTime(new Date()));
String id = new SimpleDateFormat("SSSssmmHHddMMyy").format(new Date());
account.setId(id);
account.setIdType("1");
account.setPhoneNumber(account.getUserName());
accountManager.insertAccount(account);
return "3";
} catch (Exception e) {
return "2";
}
}
}