gpt4 book ai didi

ios - ASIHTTPRequest 基本身份验证失败

转载 作者:可可西里 更新时间:2023-11-01 04:32:05 24 4
gpt4 key购买 nike

我正在使用以下代码:

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 成功验证?

最佳答案

我成功使用了:

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

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

关于ios - ASIHTTPRequest 基本身份验证失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7394768/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com