我正在为这些摄像头开发网络摄像头查看器:http://www.canvision.net/support/pt300-cgi/GetData.htm
数据到达如下:
HTTP/1.0 200 OK
Date: Wed, 19 Feb 2003 03:40:16 GMT
Server: WYM/1.0
Connection: close
Content-Type: multipart/x-mixed-replace;boundary=WINBONDBOUDARY
Last-Modified: Wed, 19 Feb 2003 03:40:16 GMT
Pragma: no-cache
Cache-Control: no-cache
Expires: 01 Jan 1970 00:00:00 GMT
--WINBONDBOUDARY
Content-Type: image/jpeg
--WINBONDBOUDARY
Content-Type: image/jpeg
这些是我的NSURLConnection委托方法:
- (void)connection:(NSURLConnection *)theConnection didReceiveData:(NSData *)data
{
[currentData appendData:data];
}
- (void)connection:(NSURLConnection *)theConnection didReceiveResponse:(NSURLResponse *)response{
NSLog(@"response with mime: %@ length:%i",[response MIMEType],[currentData length]);
if([[response MIMEType] isEqualToString:@"image/jpeg"] && [currentData length] != 0){
currentFrame = [UIImage imageWithData:currentData];
NSLog(@"valid frame");
[image setImage:currentFrame];
frameCounter++;
}
else {
NSLog(@"other data:%@",currentData);
}
currentFrame = nil;
if (currentData == receivedData1)//swap buffers
currentData = receivedData2;
else
currentData = receivedData1;
[currentData setLength:0];
[currentFrame release];
}
这一切都很好,控制台输出看起来像你期望的那样:
[Session started at 2011-02-21 20:20:39 +0100.]
2011-02-21 20:20:43.237 MotionJPEG[16330:207] response with mime: multipart/x-mixed-replace length:0
2011-02-21 20:20:43.261 MotionJPEG[16330:207] other data:<>
2011-02-21 20:20:43.262 MotionJPEG[16330:207] response with mime: image/jpeg length:0
2011-02-21 20:20:43.263 MotionJPEG[16330:207] other data:<>
2011-02-21 20:20:43.340 MotionJPEG[16330:207] response with mime: image/jpeg length:4608
2011-02-21 20:20:43.340 MotionJPEG[16330:207] valid frame
2011-02-21 20:20:43.445 MotionJPEG[16330:207] response with mime: image/jpeg length:4600
2011-02-21 20:20:43.446 MotionJPEG[16330:207] valid frame
2011-02-21 20:20:43.544 MotionJPEG[16330:207] response with mime: image/jpeg length:4580
2011-02-21 20:20:43.545 MotionJPEG[16330:207] valid frame
然而,Cam支持另一种模式,其中在jpeg之间嵌入了额外的信息:
HTTP/1.0 200 OK
Date: Wed, 19 Feb 2003 03:40:16 GMT
Server: WYM/1.0
Connection: close
Content-Type: multipart/x-mixed-replace;boundary=WINBONDBOUDARY
Last-Modified: Wed, 19 Feb 2003 03:40:16 GMT
Pragma: no-cache
Cache-Control: no-cache
Expires: 01 Jan 1970 00:00:00 GMT
--WINBONDBOUDARY
Content-Type: image/jpeg
--WINBONDBOUDARY
Content-Type: text/plain
--WINBONDBOUDARY
Content-Type: image/jpeg
--WINBONDBOUDARY
Content-Type: text/plain
在这种模式下,我希望代码正常工作,并且
将文本/普通部分写入控制台 NSLog(@"other data:%@",currentData);
线。 但是,出于某种原因,输出看起来完全一样,并且它永远不会用mime:text / plain表示响应 相反,明文部分附加到jpeg,UIImageView无法显示数据。 为什么NSURLConnection无法识别文本/普通部分? 以下是完整的来源:http://renehopf.de/MotionJPEG.zip 但为了重现这个问题,你需要相同的网络摄像头......
谢谢,
雷