gpt4 book ai didi

ios - 授权 header 在 NSMutableURLRequest 中不起作用

转载 作者:行者123 更新时间:2023-11-28 17:51:58 24 4
gpt4 key购买 nike

我正在尝试使用 NSMutableURLRequest 发送 cid=@"value"作为授权 header 。但它会引发错误。任何帮助,将不胜感激。这是我的代码

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:@"url"]];
[request setHTTPMethod:@"GET"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"value" forHTTPHeaderField:@"APIAccessKey"];
[request setValue:[NSString stringWithFormat:@"cid=\"%@\"", @"hdemPsqxVSVSJCRSt8PHmUHUyUtXk="] forHTTPHeaderField:@"Authorization"];

但是 api 返回这个错误

 <NSHTTPURLResponse: 0x7fff0a41de80> { URL: http://url } { status code: 401, headers {
"Cache-Control" = "no-cache";
"Content-Length" = 31;
"Content-Type" = "application/json; charset=utf-8";
Date = "Tue, 26 May 2015 11:36:50 GMT";
Expires = "-1";
"App-Authenticate" = "Basic Scheme='API' location='https:url";
Pragma = "no-cache";
Server = "Microsoft-IIS/7.5";
"X-AspNet-Version" = "4.0.30319";
"X-Powered-By" = "ASP.NET";
} }

最佳答案

NSMutableURLRequest* request = [[[NSMutableURLRequest alloc] initWithURL:url]
autorelease];

[request setValue:VALUE forHTTPHeaderField:@"field to set"];

或添加标题:

[request addValue:VALUE forHTTPHeaderField:@"field to set"];

关于ios - 授权 header 在 NSMutableURLRequest 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30458203/

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