gpt4 book ai didi

ios - "Stream is sending an event before being opened"

转载 作者:IT王子 更新时间:2023-10-29 05:10:20 26 4
gpt4 key购买 nike

我正在尝试使用 Swift 发出 SOAP 请求。运行截至 2014 年 9 月 9 日的最新 Xcode/iOS。我使用 NSMutableURLRequest,我将 HTTPBody 添加到请求信息中。但是,一旦我用请求启动 NSURLConnection,我就会收到错误消息“Stream xxxxxxxxx 在打开之前正在发送事件”。我没有使用任何网络库,只是一个普通的旧 NSURLConnection。关于什么可能导致此错误的任何想法?谢谢!

使用中的相关代码:

func createSOAPRequestWithEnvelope(soapEnvelope : String) {
//create request
var url = NSURL(string: "https://my-service-url")
var req = NSMutableURLRequest(URL: url, cachePolicy: NSURLRequestCachePolicy.UseProtocolCachePolicy, timeoutInterval: 5000)

req.addValue("text/xml", forHTTPHeaderField: "Content-Type")
req.HTTPMethod = "POST"
req.HTTPBody = soapEnvelope.dataUsingEncoding(NSUTF8StringEncoding)

//begin connection
var connection = NSURLConnection(request: req, delegate: self, startImmediately: false)
connection.scheduleInRunLoop(NSRunLoop.mainRunLoop(), forMode: NSDefaultRunLoopMode)

connection.start() //error happens after this command :(
}

//takes care of NTLM Authentication
func connection(connection: NSURLConnection!, didReceiveAuthenticationChallenge challenge: NSURLAuthenticationChallenge!) {
var authMethod = challenge.protectionSpace.authenticationMethod

if authMethod == NSURLAuthenticationMethodNTLM {
var credential = NSURLCredential(user: self.username,
password: self.password,
persistence: NSURLCredentialPersistence.ForSession)

challenge.sender.useCredential(credential, forAuthenticationChallenge: challenge)
}
}

func connection(connection: NSURLConnection!, didReceiveResponse response: NSURLResponse!) {
// Response received, clear out data
self.transactionData = NSMutableData()
}

func connection(connection: NSURLConnection!, didReceiveData data: NSData!) {
// Store received data
self.transactionData?.appendData(data)
}

最佳答案

Stream not Open 的问题似乎直接出在 CFNetwork 实现上。 (使用 NSConnection 和 NSSession 时可重现)。它发生在需要分 block 的请求(响应)中。此问题的副作用是 Windows 身份验证无法正常工作,每个请求都需要经过完整的握手过程。并且在 iOS 8.1 中也没有修复。

关于ios - "Stream is sending an event before being opened",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25755555/

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