简体   繁体   English

XCODE iPhone上用于基本身份验证的HTTP标头

[英]HTTP Headers for Basic Authentication on XCODE iPhone

I want to show one webpage. 我想显示一个网页。 To show that webpage, I need to put a token (that I already have) that will be given in the HTTP Header in the "Authorisation" field. 为了显示该网页,我需要放置一个令牌(已经拥有),该令牌将在“授权”字段的HTTP标头中给出。

for the moment, I try to use that code : 目前,我尝试使用该代码:

NSString *authHeader = [@"Basic " stringByAppendingFormat:@"%@", token ];
    NSURLRequest *requestObject = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://xxx.com/api_dev.php/1308149125"]];

And then after, I put the webpage into the webView (This code is running): 然后,将网页放入webView(此代码正在运行):

[webView loadRequest:requestObject];//load the URL into the web view.
    [self.view addSubview:webView];//add the web view to the content view.

Thanks for help me 谢谢帮我

Just put 刚放

NSString *authHeader = [@"" stringByAppendingFormat:@"%@", token ;
    NSMutableURLRequest *requestObject = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://xxx.com/1308149125"]];
    [requestObject setValue:authHeader forHTTPHeaderField:@"App-Token"];

So, add the last line, and delete the "Basic " before the token 因此,添加最后一行,并删除令牌之前的“基本”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM