NSURLConnection didReceiveResponse не распознает несколько типов MIME - PullRequest
1 голос
/ 22 февраля 2011

Я работаю над средством просмотра веб-камеры, для этих камер: 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 Delegate: - (void)connection:(NSURLConnection *)theConnection didReceiveData:(NSData *)data { [currentData appendData:data]; }</p> <ul> <li>(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;<br> else currentData = receivedData1;<br> [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 поддерживает другой режим, где дополнительная информация встроена между jpegs:

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 но чтобы воспроизвести проблему, вам понадобится та же веб-камера ...

Спасибо

Rene

...