info.plist根据以下错误消息,我需要在我的设置中启用HTTP模式?
传输安全性阻止了明文HTTP(http://)资源加载,因为它不安全.可以通过应用程序的Info.plist文件配置临时例外.
假设我的域名是example.com.
我将Xcode更新为7.0或iOS 9.0时遇到问题.不知怎的,它开始给我标题错误
"无法加载资源,因为App Transport Security策略要求使用安全连接"
Web服务方法:
-(void)ServiceCall:(NSString*)ServiceName :(NSString *)DataString
{
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
[sessionConfiguration setAllowsCellularAccess:YES];
[sessionConfiguration setHTTPAdditionalHeaders:@{ @"Accept" : @"application/json" }];
NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@",ServiceURL]];
NSLog(@"URl %@%@",url,DataString);
// Configure the Request
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setValue:[NSString stringWithFormat:@"%@=%@", strSessName, strSessVal] forHTTPHeaderField:@"Cookie"];
request.HTTPBody = [DataString dataUsingEncoding:NSUTF8StringEncoding];
request.HTTPMethod = @"Post";
// post the request and handle response
NSURLSessionDataTask *postDataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error)
{
// Handle the …Run Code Online (Sandbox Code Playgroud) 我在iBooks中阅读了Apple编程语言Swift,但无法弄清楚如何在Swift中创建一个http请求(类似于CURL).我是否需要导入Obj-C类或者我只需要导入默认库?或者是否无法基于本机swift代码发出HTTP请求?
有iOS 9 beta 1的人有这个问题吗?
我使用标准NSURLConnection连接到web服务,一旦调用webservice我就得到以下错误.这目前在iOS 8.3中有效
可能的beta bug?任何想法或想法都会很棒!我知道它在iOS 9开发的早期阶段
这是完整的错误:
CFNetwork SSLHandshake失败(-9824)NSURLSession/NSURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9824)
NSURLRequest * urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://mywebserviceurl"]];
NSURLResponse * response = nil;
NSError * error = nil;
NSData * data = [NSURLConnection sendSynchronousRequest:urlRequest
returningResponse:&response
error:&error];
Run Code Online (Sandbox Code Playgroud) 我通过push segue呈现视图控制器后,在使用Swift2在Xcode7中运行代码时出现以下错误:
_BSMachError: (os/kern) invalid capability (20)
_BSMachError: (os/kern) invalid name (15)
Run Code Online (Sandbox Code Playgroud)
其他SO文章没有解决方案,是否有人知道这个问题?
我使用在我的开发箱上运行的本地服务器开发我的iOS应用程序.在设备上进行测试时,我通过IP地址直接连接,该地址是通过HTTP而不是HTTPS(因此我不需要在开发过程中处理自签名证书,设备甚至不喜欢这样做).
我认为这就足够了:

但是,如果没有添加也无法让它工作NSAllowsArbitraryLoads = YES,AKA:

现在,我将不得不记得在滚动生产版本时删除它,而不是在开发期间删除... arg.是否应该NSExceptionDomains使用IP地址,如果没有,还有什么我可以做而不启用NSAllowsArbitraryLoads?
我目前正在研究Xcode 7 beta 6.我正在尝试向http://mySubdomain.herokuapp.com发送"删除"请求
我收到的错误是:
App Transport Security已阻止明文HTTP(http://)资源加载,因为它不安全.可以通过应用程序的Info.plist文件配置临时例外.
进行API调用时出错:Error Domain = NSURLErrorDomain Code = -1022无法加载资源,因为App Transport Security策略要求使用安全连接.
NSLocalizedDescription =无法加载资源,因为App Transport Security策略需要使用安全连接.,NSUnderlyingError = 0x796f7ef0 {错误域= kCFErrorDomainCFNetwork代码= -1022"(null)"}}
在我的实际API调用中,我使用"https"而不是"http",这实际上适用于我的POST请求.但是DELETE请求会抛出上述错误.
我在这里看到了涉及pList文件的解决方案,但它们都没有对我有用.我在下面列出了我的尝试.
第一次尝试:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Run Code Online (Sandbox Code Playgroud)
第二次尝试:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>herokuapp.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSExceptionMinimumTLSVersion</key>
<string>TLSv1.2</string>
<key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSThirdPartyExceptionMinimumTLSVersion</key>
<string>TLSv1.2</string>
<key>NSRequiresCertificateTransparency</key>
<false/>
</dict>
</dict>
</dict>
Run Code Online (Sandbox Code Playgroud)
最后,我甚至将所有这些临时密钥都放入:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>herokuapp.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSTemporaryIncludesSubdomains</key>
<true/>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key> …Run Code Online (Sandbox Code Playgroud) 我开始了一个空白的tvOS项目并创建了以下代码:
- (void)viewDidLoad
{
[super viewDidLoad];
AVPlayer *avPlayer = [AVPlayer playerWithURL:[NSURL URLWithString:@"http://www.myurl.com/myvideo.mp4"]];
AVPlayerLayer *avPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:avPlayer];
avPlayerLayer.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
[self.view.layer addSublayer:avPlayerLayer];
[avPlayer play];
}
Run Code Online (Sandbox Code Playgroud)
一旦应用加载,模拟器中没有任何事情发生.没有视频,没有,只是我的Apple TV模拟器中的空白半透明屏幕.
从HTTP源播放Apple TV应用程序的应用程序启动示例视频的正确方法是什么?
我收到自签名证书的错误
错误域= NSURLErrorDomain代码= -1200"发生SSL错误,无法与服务器建立安全连接.
同时测试我的一个演示应用程序的Web服务
注意: 在假设其重复之前,我会请求请一直阅读,即使我已向苹果开发论坛报告过
使用Alamofire图书馆
func testAlamofireGETRequest() -> Void
{
Alamofire.request(.GET, "https://filename.hostname.net/HelloWeb/service/greeting/john")
.responseJSON
{ response in
print("Response JSON: \(response.result.value)")
}
}
Run Code Online (Sandbox Code Playgroud)
使用NSURLSession
func testNSURLSessionRequest() -> Void {
let session = NSURLSession.sharedSession()
let urlString = "https://filename.hostname.net/HelloWeb/service/greeting/john"
let url = NSURL(string: urlString)
let request = NSURLRequest(URL: url!)
let dataTask = session.dataTaskWithRequest(request) { (data:NSData?, response:NSURLResponse?, error:NSError?) -> Void in
print("done, error: \(error)")
//Error Domain=NSURLErrorDomain Code=-1200 "An …Run Code Online (Sandbox Code Playgroud) 嗨,我是Swift的初学者,我正在尝试使NSURLSession"发布"请求发送一些参数,如下面的代码
根据我的下面的代码响应不是来自服务器可以有人帮助我
import UIKit
protocol sampleProtocal{
func getResponse(result:NSDictionary)
func getErrorResponse(error:NSString)
}
class BackGroundClass: NSObject {
var delegate:sampleProtocal?
func callPostService(url:String,parameters:NSDictionary){
print("url is===>\(url)")
let request = NSMutableURLRequest(URL: NSURL(string:url)!)
let session = NSURLSession.sharedSession()
request.HTTPMethod = "POST"
//Note : Add the corresponding "Content-Type" and "Accept" header. In this example I had used the application/json.
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.addValue("application/json", forHTTPHeaderField: "Accept")
request.HTTPBody = try! NSJSONSerialization.dataWithJSONObject(parameters, options: [])
let task = session.dataTaskWithRequest(request) { data, response, error in
guard data != nil else {
print("no …Run Code Online (Sandbox Code Playgroud)