Reputation: 27
when I send a request to the the server with string in hebrew the request doesn't sent to the server, if I change the string to english it is work.
this is the code:
NSString *feedtextMsg = @"היי";
URLString = [NSString stringWithFormat:@"%@messagePage.php?swAction=takeFeedback&se=%@&fid=%@&autx=%@&msg=%@",sUrl,userID,anonymousUID,autx,feedtextMsg];
[self scaleFeedImage:feedBackPhoto];
NSData *storeData = UIImageJPEGRepresentation(feedBackPhoto, 90);
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:URLString]];
[request setHTTPMethod:@"POST"];
NSString *boundary = @"---------------------------14737809831466499882746641449";
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
[request addValue:contentType forHTTPHeaderField:@"Content-Type"];
NSMutableData *body = [NSMutableData dataWithBytes: [URLString UTF8String] length: [URLString lengthOfBytesUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"file\"; filename=\"%@.jpg\"\r\n", @"the"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:storeData]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];
sendreq = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
response =[[NSString alloc] initWithBytes:[sendreq bytes] length:[sendreq length] encoding:NSUTF8StringEncoding];
NSLog(@"res1: %@", response);
so if I change the string
NSString *feedtextMsg = @"היי";
to this
NSString *feedtextMsg = @"HI";
I get response from my PHP file.
in my PHP file the code is
die("res: ".$_Get["msg"]);
what should I do to make it work ?
Upvotes: 0
Views: 41
Reputation: 2097
According to the documentation, +[NSURL URLWithString:]
requires the URL string to conform to RFC 2396, which excludes Unicode characters. You could send the text in your form data or use percent aka. URL encoding.
Upvotes: 2