Objective-C的HTTP基本身份验证 [英] Objective-c HTTP Basic authentication

查看:215
本文介绍了Objective-C的HTTP基本身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将如何去在Objective-C复制此

How would i go about replicating this in objective-c

curl -u rick@email.com:mypassword http://foo.lighthouseapp.com/projects.xml

我一直在玩与周围的ASIHTT prequest库,但似乎无法弄清楚,

I've been playing around with the ASIHTTPRequest library but can't seem to figure it out,

显然发送我的要求,像这样将返回认证错误:

obviously sending my request like so returns an authentication error:

-(void)submit:(id)sender {
    NSURL *url = [NSURL URLWithString:@"http://ldn.lighthouseapp.com/projects/63254-londonist-20/tickets.xml"];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request startSynchronous];
    NSError *error = [request error];
    if (!error) {
        NSString *response = [request responseString];
        NSLog(@"response:%@",response);
    } else {
        NSLog(@"error:%@",error);
    }
}

这可能是很简单的我只是失去了一些东西pretty各大

This is probably very simple i'm just missing something pretty major

推荐答案

<一个href=\"http://allseeing-i.com/ASIHTT$p$pquest/How-to-use#specifying_a_username_and_password_to_use_in_the_url\"相对=nofollow>从ASIHTT prequest文档

与请求头

[request addRequestHeader:@"Authorization"
                    value:[NSString stringWithFormat:@"Basic %@",
                           [ASIHTTPRequest base64forData:
                            [[NSString stringWithFormat:@"%@:%@", theUsername, thePassword]
                             dataUsingEncoding:NSUTF8StringEncoding]]]];

这篇关于Objective-C的HTTP基本身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆