我想上传HTTP下的线性文件流模式。 我们的想法是这样做同时几步之遥,1)线索1:录制音频文件并将其存储在一个临时文件2)主题2:取N从临时文件的字节,并将其发送到HTTP服务器。
我怎么能写在HTTP流?在CFHTTPStream我没有看到写的方法,只读:■我需要使用套接字? 谢谢!!!
我实际的代码
CFWriteStreamRef stream;
NSString *strUrl = @"myurl";
NSURL *url = [[[NSURL alloc] initWithString:strUrl] retain];
CFStringRef requestMethod = CFSTR("GET");
CFHTTPMessageRef message= CFHTTPMessageCreateRequest(kCFAllocatorDefault, requestMethod, (CFURLRef)url, kCFHTTPVersion1_1);
CFHTTPMessageSetHeaderFieldValue(message, CFSTR("Content-Type"),
CFSTR("multipart/form-data"));
stream = ?? //CFReadStreamCreateForHTTPRequest(NULL, message);
CFRelease(message);
//other headers...
if (CFWriteStreamSetProperty(stream, kCFStreamPropertyHTTPShouldAutoredirect, kCFBooleanTrue) == false)
{
NSLog(@"Error");
return NO;
}
//
// Open the stream
//
if (!CFWriteStreamOpen(stream))
{
CFRelease(stream);
NSLog(@"Error");
return NO;
}
CFStreamClientContext context = {0, self, NULL, NULL, NULL};
CFWriteStreamSetClient(stram, kCFStreamEventHasBytesAvailable | kCFStreamEventErrorOccurred | kCFStreamEventEndEncountered,
RSWriteStreamCallBack,
&context);
CFWriteStreamScheduleWithRunLoop(stream, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);