【发布时间】:2011-10-06 14:10:50
【问题描述】:
我正在尝试从 ios 访问安全 URL。基本上 url 会提示用户用户名和密码。如何从 ios 发送用户名和密码?
我的代码 这是我用来访问 JSON Parser 的方法
- (NSString *)stringWithUrl:(NSURL *)url{
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url
cachePolicy:NSURLRequestReturnCacheDataElseLoad
timeoutInterval:30];
// Fetch the JSON response
NSData *urlData;
NSURLResponse *response;
NSError *error;
// Make synchronous request
urlData = [NSURLConnection sendSynchronousRequest:urlRequest
returningResponse:&response
error:&error];
// Construct a String around the Data from the response
return [[[NSString alloc] initWithData:urlData encoding:NSUTF8StringEncoding] autorelease];}
- (id) objectWithUrl:(NSURL *)url{
SBJsonParser *jsonParser = [[[SBJsonParser alloc]init] autorelease];
NSString *jsonString = [self stringWithUrl:url];
// Parse the JSON into an Object
return [jsonParser objectWithString:jsonString error:nil]; }
这是我在字典中检索 json 键的一段代码。
- (NSDictionary *) downloadFeed {
id response = [self objectWithUrl:[NSURL URLWithString:@"http://mysite.com/Services/Secure.svc/GetList?id=2127"]];
NSDictionary *feed = (NSDictionary *)response;
return feed; }
谁能告诉我在哪里可以将用户名和密码传递给这个网址?
【问题讨论】:
-
提示是什么意思?网站上的登录表单,或basic HTTP authentication?
-
基本 HTTP 身份验证,我更新了我的代码以获得更清晰的图片!
-
放在这里:
http://user:passwd@mysite.com/...
标签: objective-c ios