2
ConfirmChallenge:(id)sender{
//  NSError *err;
NSStringEncoding encoding;
NSError *error;
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
SBJsonWriter *jsonWriter = [[SBJsonWriter alloc] init];
// NSString *jsonString = [jsonWriter stringWithObject:appDelegate.userSelection];
//    NSString *sendChallengeInfo = [appDelegate.URL stringByAppendingString: [NSString                stringWithFormat:@"FirstPickService/SaveChallenge?jsonChallengeDTO=%@",appDelegate.userSelection]];
 NSData* jsonData = [NSJSONSerialization dataWithJSONObject:appDelegate.userSelection options:kNilOptions     error:&error];

NSString *sendChallengeInfo = [appDelegate.URL stringByAppendingString:[NSString     stringWithFormat:@"FirstPickService/SaveChallenge?jsonChallengeDTO=%@",jsonData]];



//NSLog(@"send challenge info%@",appDelegate.userSelection);
//NSURL *JsonURLIN = [NSURL URLWithString:sendChallengeInfo];
//NSString *JsonDataIN = [[NSString alloc] initWithContentsOfURL:JsonURLIN  usedEncoding:&encoding  error:&error];
//NSLog(@"return value=%@",JsonDataIN);
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:sendChallengeInfo]];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/json;charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setHTTPBody:jsonData];
NSLog(@"jsondata=%@",sendChallengeInfo);
//NSLog(@"working");
[NSURLConnection connectionWithRequest:request delegate:self];
}

从上面 jsonData 作为参数发送到下面的 RestFul 服务

@Produces("text/plain")
@GET              
@Path("/SaveChallenge")   
public String saveChallenge(@QueryParam("jsonChallengeDTO") JSONObject jsonObject) {                                                   
    String  data = jsonBusiness.createChallenge(jsonObject); 
    return data;             
}

这里的问题是“无法接收从 ios 发送的数据”。

提前致谢

4

0 回答 0