Obj-C,请求没有发送

时间:2014-11-30 01:38:51

标签: objective-c

当我用希伯来语中的字符串向服务器发送请求时,请求不会发送到服务器,如果我将字符串更改为英语则可以正常工作。

这是代码:

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

所以如果我改变字符串

NSString *feedtextMsg = @"היי";

到这个

NSString *feedtextMsg = @"HI";

我收到了PHP文件的回复。

在我的PHP文件中,代码是

die("res: ".$_Get["msg"]);

我该怎么做才能让它发挥作用?

1 个答案:

答案 0 :(得分:2)

根据the documentation+[NSURL URLWithString:]要求URL字符串符合RFC 2396,后者不包括Unicode字符。您可以在表单数据中发送文本或使用百分比aka。网址编码。