iPhone NSData / NSUrl with cookie [英] iPhone NSData/NSUrl with cookie
问题描述
我正在尝试播放/串流网站上托管的mp3。网站需要设置Cookie标头,但我无法设置或获取容器来为我执行此操作。
I'm trying to play/stream a mp3 hosted on a website. The site requires a cookie header to be set, but I'm having trouble setting that or getting the container to do that for me.
NSURL *sampleUrl = [NSURL URLWithString:@"http://domain/files/sample.mp3"];
NSData *sampleAudio = [NSData dataWithContentsOfURL:sampleUrl];
到目前为止,我一直在使用jQuery来做/管理XMLHTTPRequests,不得不调用本地代码来流式传输音频。它看起来不像是由本机HTTP请求拾取。
Up until this point, I've been using jQuery to do/manage XMLHTTPRequests, but I've had to call into native code to stream the audio. It doesn't look like the cookie is getting picked up by the native HTTP request.
有没有将Cookie注入上述请求,或者确保针对给定域添加了Cookie?
Is there anyway to inject the cookie into the above request, or otherwise ensure that a cookie gets added against a given domain?
感谢
推荐答案
确定,所以这样做的方式不是注入头,而是设置一个cookie管理器总是接受cookie。然后将cookie传递到后续请求。
Ok, so the way to do this is not injecting headers but setting a cookie manager to always accept cookies. This will then pass on the cookie to subsequent requests.
NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
[cookieStorage setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
Robbie
这篇关于iPhone NSData / NSUrl with cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!