Search code examples
iphonejsonhttppostsbjson

Sending JSON to IIS from iPhone in hebrew the string cut before the end


Im sending data to a server from my iPhone app, with this code:

- (void) sendGeneral:(NSString *) general{
    self.responseData = [NSMutableData data];

    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:CBURL]];  
    [request setHTTPMethod:@"POST"];

    sendString = [[NSMutableString alloc] initWithString:general];

    requestData = [NSMutableData dataWithBytes:[sendString UTF8String] length:[sendString length]];
    [request setHTTPBody:requestData];

    [[NSURLConnection alloc] initWithRequest:request delegate:self];
}

As long as I send latin in the data it all sent well and the server getting the full string when I'm sending hebrew data in it it is cut some where and the server dosent get all data, on Xcode debug I can see the full string as I use NSLog to output it:

{"Session":{"customer_id":-1,"client_time":"3","user_id":-1,"device_token":"3"},"Error":{"error_code":-1,"error_message":"3"},"Successful":{"success_code":-1,"success_message":"3"},"Details":{"StartCallID":-1,"user_password":"כ","user_name":"ככ","StartDate":"3","EndDate":"3"},"Ptype":{"Ptype":3}}

can some one help?


Solution

  • I'm not entirely sure this will fix your problem, is hebrew UTF8 or UTF16?? My guess is you're getting cut off about halfway through the data? That would imply that sendString length returns only half the number of bytes if it's UTF16.

    A better way to do this would be as such:

    
    [request setHTTPBody:[general dataUsingEncoding:NSUTF8StringEncoding]];
    // or if it's UTF16 
    [request setHTTPBody:[general dataUsingEncoding: NSUnicodeStringEncoding]];