我正在尝试将我的输入流转换为字符串。我尝试转换的输入流是NSURLRequest.HTTPBodyStream,显然httpbody被设置为空,并在您发出请求后被替换为流。我该怎么做呢?这就是我到目前为止所知道的:
#define MAX_UTF8_BYTES 6
NSString *utf8String;
NSMutableData *_data = [[NSMutableData alloc] init]; //for easy 'appending' bytes
int bytes_read = 0;
while (!utf8String) {
if (bytes_read > MAX_UTF8_BYTES) {
NSLog(@"Can't decode input byte array into UTF8.");
break;
}
else {
uint8_t byte[1];
[r.HTTPBodyStream read:byte maxLength:1];
[_data appendBytes:byte length:1];
utf8String = [NSString stringWithUTF8String:[_data bytes]];
bytes_read++;
}
}当我打印字符串时,它要么总是空的,要么只包含一个字符,甚至不打印null。有什么建议吗?
https://stackoverflow.com/questions/41292779
复制相似问题