问题标签 [nsurlcredential]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
0 回答
961 浏览

objective-c - How does (NSURLCredential *) proposedCredential in iOS work?

Morning

I've been working on creating a iOS application that uses stored credentials in NSURLCredentialStorage for a specific protectionspace. I've now gotten to the point where I'm using proposedCredential to fetch the stored credentials.

My problem is that it is returning null, and I can't seem to find any good explanation on what proposedCredential actually does and why it isn't returning what I think it should.

This is what I'm doing:

First I define a NSURLProtectionSpace, give credentials and store them in the NSURLCredentialStorage. I've already checked that this is being done before I'm referencing proposedCredential and that the credentials that I'm passing on are correct.

Could someone tell me what proposedCredential actually does, what it compares together to figure out if there is a credential that it should pass on, and what it is that I'm possibly missing from the code?

For reference, I've been reading the Apple doc, specifically this, this, and this

All help would be appreciated.

0 投票
3 回答
38514 浏览

iphone - NSURLErrorDomain 错误 -1012

我需要从受密码保护的 URL 解析 xml 文件我尝试了以下操作

我得到以下回复

连接错误==错误域=NSURLErrorDomain代码=-1012“操作无法完成。(NSURLErrorDomain错误-1012。)”UserInfo=0x6e51b90 {NSErrorFailingURLKey= http://example.com/api/ID/password/ xml/ ,

任何帮助表示赞赏!

0 投票
1 回答
4080 浏览

ios - 如何从 Webserver 获取 cookie 并在 iOS 应用程序中维护它?

我想从http://mycompany.com/page1...http://mycompany.com/page2获取 JSON ...在网络服务器端,它需要初始登录http://mycompany.com /login,然后为用户维护一个 cookie。如何使用 NSURLConnection 获得这种行为,而不必每次都要求登录?这是使用 NSURLCredential 存储的非工作代码。我是否需要在登录时从 web 服务获取 cookie,然后将其与以后的请求一起发送?我为此苦苦挣扎了一段时间,所以你能澄清你的答案吗?

0 投票
1 回答
508 浏览

objective-c - 使用 NSURLCredential 绕过自签名证书,同时传入用户名和密码

我需要绕过带有 UIWebView 的自签名证书,同时还能够传入用户名和密码进行身份验证。

NSURLCredential *credential = [NSURLCredential credentialWithUser:@"username" 密码:@"password" persistence:NSURLCredentialPersistenceNone];

两者都是单独有效的,当我尝试将它们结合起来时,它们都会大惊小怪......有什么想法吗?

0 投票
1 回答
348 浏览

ios - NSURLCredential 密码偶尔返回无密码

NSURLCredential 的 Apple 文档说它可能并不总是返回密码。但是除了没有密码与凭证一起存储的明显原因之外,还有什么理由永久存储在 NSURLCredentialStorage 中的默认凭证会随机返回没有密码?

奇怪的是它工作正常的时间百分比。但偶尔读取默认凭据上的密码属性会返回 nil。credential 对象在其他方面似乎是有效的,但 password 属性只返回 nil。

密码读取发生在不是主线程的线程中,所以我想知道是否存在线程限制,尽管我在文档中找不到任何内容。

是否有可能我们需要在一段时间后重试获取密码?

0 投票
1 回答
1456 浏览

objective-c - NSURLCredentialStorage sharedCredentialStorage 不返回有效的凭据

我对 sharedCredentialStorage 有疑问。它不会返回预期的凭据,即使保护空间的所有参数(主机、端口、...)与我之前设置的参数相同。

设置 defaultCredential 的代码:

运行这段代码并转到 gdb 窗口后,allCredentials(在 sharedCredentialStorage 中)的结果给出:

这意味着凭据已正确添加到 sharedCredentialStorage。

但是当 http 请求操作发生并且身份验证挑战弹出并运行此代码时:

没有任何内容返回到凭证变量。你知道为什么会这样吗?

gdb 的输出给出:

还有一件事,即使我使用一些字符串作为领域(并在我的 REST Web 服务中正确设置它)它也不起作用。

0 投票
1 回答
78 浏览

iphone - 服务器信任问题

我们的应用程序正在生产中,今天我们遇到了一个问题“此服务器的证书无效。您可能正在连接到伪装成“server.name”的服务器,这可能会使您的机密信息面临风险。

我们正在使用通过 https 的连接。

之前没有这样的问题。为什么现在同样给出这个错误。它甚至没有连接到服务器。

0 投票
2 回答
257 浏览

ios - UIAlertView 中的 NSCredential 以连接到 WebService

我有一个包含 ViewControllers 的 NavigationController,但我希望它能够通过 UIAlertView 访问一些 ViewControllers 的身份验证。(一些 ViewControllers 内容需要认证)。

该 UIAlertView 将向 Web 服务发送数据以首先检查登录名和密码是否正确,然后接收回数据 + 存储在 Iphone 中的令牌(就像您只需要进行一次身份验证一样)。

如果用户已经通过身份验证,我将在访问之前检查每个 ViewControllers,方法是检查令牌是否已在 Iphone 中注册。

但我真的不知道如何才能弄清楚所有事情,我的意思是特别是使所有事情都能正常工作的架构:UIAlertView、NSCredential、在 Iphone 中存储光数据等......

任何人都可以清除我的想法吗?

0 投票
1 回答
657 浏览

cocoa - 带有 UTF8 密码的 NSURLRequest

这是我编写的用于连接到服务器并获取用户身份验证令牌的方法:

然后一个 URL 看起来像这样:https://username:hello%C2%B0@api.example.com/v1/user/api_token?format\=json,其中密码是hello°。该URLEncodedString方法正确地编码了示例中的所有内容,但请求永远不会起作用。问题不在于转义或服务器,因为我可以curl使用相同的 URL,并且我得到了很好的 JSON 和身份验证工作,即使密码中有一个非 ASCII 字符。它也适用于其他编程语言,如rubyor python。但是相同的 url 永远无法使用,NSURLConnection而且它在 Safari 中也无法使用,当然它使用NSURLConnection. 我每次都收到“无法完成操作”和“401 禁止”。

(当密码只包含 ASCII 字符时,我的代码可以正常工作。我也尝试使用这些NSURLCredential方法,同样的问题。)

我需要做什么才能使用密码包含非 ASCII 字符NSURLConnection的 URL ?https://username:hello%C2%B0@api.example.com/v1/user/api_token?format\=json

0 投票
2 回答
647 浏览

ios - NSURLCredential 在没有任何信息的情况下崩溃 - 基于证书的身份验证

在我的应用程序中,我需要根据证书对用户进行身份验证。我就是这样做的 1. 首先,我将证书导出到沙箱中。2. 然后我从证书中提取 SecIdentityRef,将其添加到钥匙串中,然后从沙箱中删除证书。3. 当我实际将此身份传递给 NSURL 连接的身份验证质询时,应用程序会崩溃而没有提供任何有意义的信息。

以下是所有相关的代码片段

在身份验证质询中传递此凭据

一旦我将此凭据传递给 NSURLChallenge 发件人,应用程序就会崩溃。

在此处输入图像描述

任何帮助是极大的赞赏!!!