ASIHTTPRequest 基本身份验证失败

发布于 2024-12-04 03:43:20 字数 1219 浏览 4 评论 0原文

我正在使用以下代码:

NSString *params = [NSString stringWithFormat:@"{\"username\": \"%@\", \"password\": \"%@\", \"client_id\": \"%@\", \"client_secret\": \"%@\"}",
                    mFieldUsername.text, mFieldPassword.text, [NTDefaults clientId], [NTDefaults clientSecret]];
NSLog(@"Params:\n%@", params);

NSURL *url = [NSURL URLWithString:[[NTDefaults baseEndpointUrl] stringByAppendingString:@"/api/token.json"]];
ASIHTTPRequest *request = [ASIFormDataRequest requestWithURL:url];
[request addRequestHeader:@"Content-Type" value:@"application/json"];
[request addRequestHeader:@"Content-Length" value:[NSString stringWithFormat:@"%d",params.length]];
[request setAuthenticationScheme:(NSString *) kCFHTTPAuthenticationSchemeBasic];
[request setUsername:@"user"];
[request setPassword:@"pass"];
[request setShouldPresentCredentialsBeforeChallenge:YES];

[request setPostBody:[params dataUsingEncoding:NSUTF8StringEncoding]];

NSLog(@"Post Body: %@", request.postBody);
NSLog(@"Headers: %@", request.requestHeaders);
NSLog(@"URL: %@", url.absoluteString);
[request setDelegate:self];
[request startAsynchronous];

正在返回:

错误:需要身份验证

有人对此有任何想法吗?使用 ASIHTTPRequest 成功进行身份验证?

I am using the following code:

NSString *params = [NSString stringWithFormat:@"{\"username\": \"%@\", \"password\": \"%@\", \"client_id\": \"%@\", \"client_secret\": \"%@\"}",
                    mFieldUsername.text, mFieldPassword.text, [NTDefaults clientId], [NTDefaults clientSecret]];
NSLog(@"Params:\n%@", params);

NSURL *url = [NSURL URLWithString:[[NTDefaults baseEndpointUrl] stringByAppendingString:@"/api/token.json"]];
ASIHTTPRequest *request = [ASIFormDataRequest requestWithURL:url];
[request addRequestHeader:@"Content-Type" value:@"application/json"];
[request addRequestHeader:@"Content-Length" value:[NSString stringWithFormat:@"%d",params.length]];
[request setAuthenticationScheme:(NSString *) kCFHTTPAuthenticationSchemeBasic];
[request setUsername:@"user"];
[request setPassword:@"pass"];
[request setShouldPresentCredentialsBeforeChallenge:YES];

[request setPostBody:[params dataUsingEncoding:NSUTF8StringEncoding]];

NSLog(@"Post Body: %@", request.postBody);
NSLog(@"Headers: %@", request.requestHeaders);
NSLog(@"URL: %@", url.absoluteString);
[request setDelegate:self];
[request startAsynchronous];

Which is returning:

Error: Authentication needed

Does anybody have any ideas on this? Successfully authenticated using ASIHTTPRequest?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

回眸一遍 2024-12-11 03:43:20

我成功使用:

request.shouldPresentCredentialsBeforeChallenge = YES;
[request addBasicAuthenticationHeaderWithUsername:@"myUser"
                                      andPassword:@"myPass"];

我不使用 setAuthenticationScheme 进行基本身份验证。

I successfully use:

request.shouldPresentCredentialsBeforeChallenge = YES;
[request addBasicAuthenticationHeaderWithUsername:@"myUser"
                                      andPassword:@"myPass"];

I do not use setAuthenticationScheme for my basic authentication.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文