是否可以设置为 http 正文而不是编码字符串?
NSData *postData = [postString dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:postData];
是否有可能做这样的事情:
NSString *postLength = [NSString stringWithFormat:@"%d", [postString length]];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:postString];
我试过这个并得到一个错误:由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[__NSCFString bytes]:无法识别的选择器发送到实例