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 から送信されたデータを受信できない」ことです。
前もって感謝します