POST数据目标C:AppendString和AppendData

时间:2019-05-30 12:46:05

标签: objective-c post

我使用两种方法来创建用于从我的应用发送数据的帖子主体。我面临的问题是使用AppendData方法发送诸如撇号之类的字符。

appendString方法可以正常工作,无论有没有撇号,我都可以在目标URL上阅读帖子。我使用诸如以下的appendString准备postStringBody:

[postStringBody appendString:[NSString stringWithFormat:@"Id=%@", itemId]];
[postStringBody appendString:[NSString stringWithFormat:@"&comment=%@", commentText]];

当发送带有注释的图像时,将使用appendData方法。图像效果很好,如果没有撇号,注释也是如此。但是,如果注释中带有撇号,我将无法在目标URL处检测到任何commentText:

NSMutableData *body = [NSMutableData data];

... add image data to body ....

NSMutableDictionary *dictComment = [[NSMutableDictionary alloc] init];
[dictComment setObject:[NSString stringWithFormat:@"%@", commentText] forKey:@"imageComment"];
[body appendData:[self createFormData:dictComment withBoundary:boundary]];

[postStringBody setHTTPBody:body];

我创建引起问题的帖子数据的方式是否有所不同?

0 个答案:

没有答案