0

I want to post NSDictionary to java based web service. But, web service not responding to my call. Please go through the below code:

server side code:(Java web service):

@Consumes("application/json")
    @POST             
    @Path("/SaveChallenge")  
    public String saveChallenge(@QueryParam("jsonChallengeDTO") JSONObject jsonChallengeDTO) {                                              
        String data = "";      
            data = jsonBusiness.createChallenge(jsonChallengeDTO);
        return data;            
    } 

Client side code:(From IOS mobile app)

NSError *error;
    AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];


NSData* jsonData = [NSJSONSerialization dataWithJSONObject:appDelegate.userSelection options:kNilOptions error:&error];

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

    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];

    [NSURLConnection connectionWithRequest:request delegate:self];

Here **appDelegate.userSelection** is the NSMutableDictionary, that I want to post to web service.

Instead of trying with JSon, when tried with String, we are able to post data to web service.

Please review and let me know where I am wrong.

Thanks in advance,

Ramu Pasupuleti
  • 888
  • 2
  • 15
  • 35

0 Answers0