Objective-c HTTP 基本身份验证
我如何在 Objective-C 中复制这个
curl -u [email protected]:mypassword http://foo.lighthouseapp.com/projects.xml
我一直在使用 ASIHTTPRequest 库,但似乎无法弄清楚,
显然像这样发送我的请求会返回一个身份验证错误:
-(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);
}
}
这可能非常简单,我只是错过了一些非常重要的东西
How would i go about replicating this in objective-c
curl -u [email protected]:mypassword http://foo.lighthouseapp.com/projects.xml
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);
}
}
This is probably very simple i'm just missing something pretty major
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果不想使用任何框架(像我一样),你可以通过以下方式进行:
If don't want use any frameworks (like me) you can do in the next way:
来自 ASIHTTPRequest 文档
带有请求标头
From ASIHTTPRequest Documentation
With a Request Header
如果您使用 ASIHTTPRequest,则需要执行以下操作:
If you are using ASIHTTPRequest, this is all that is needed: