0

X-Transmission-Session-Id を取得するためにこのコードを使用しましたが、更新されたヘッダーでリクエストを再送信する必要があります。

function takeXTransmissionSessionId( ){

    let urls = NSURL(string: "\(url)")
    let task = NSURLSession.sharedSession().dataTaskWithURL(urls!) { (data, respornse, error) -> Void in

        guard error == nil && data != nil else {

            print("error=\(error!)")

            let alertView = UIAlertController(title: "ERROR", message: "A server with the specified hostname could not be found.", preferredStyle: UIAlertControllerStyle.Alert)
            let actionView = UIAlertAction(title: "OK", style: UIAlertActionStyle.Cancel, handler: nil)
            alertView.addAction(actionView)
            self.presentViewController(alertView, animated: true, completion: nil)

            return
        }

        if let httpStatus = respornse as? NSHTTPURLResponse where httpStatus.statusCode != 200 {

            let sesionID = httpStatus.allHeaderFields["X-Transmission-Session-Id"]

            if sesionID == nil {

                let alertView = UIAlertController(title: "ERROR", message: "The request has not been applied because it lacks valid authentication credentials for the target resource.", preferredStyle: UIAlertControllerStyle.Alert)
                let actionView = UIAlertAction(title: "OK", style: UIAlertActionStyle.Cancel, handler: nil)
                alertView.addAction(actionView)
                self.presentViewController(alertView, animated: true, completion: nil)

            }else{

                //print("\(respornse!)")
                //print("\(sesionID!)")
                self.XTransmissionSessionId = "\(sesionID!)"

            }

        }

    }

    task.resume()

}

私の問題は、さまざまな方法で何度もトレイを作成することですが、何をする必要があるのか​​ わかりません。

ありがとう!

4

1 に答える 1

0

これは、私が必要とすることを行うためのコードです:

request.HTTPMethod = "POST"
    request.addValue("\(XTransmissionSessionId)", forHTTPHeaderField: "X-Transmission-Session-Id")
于 2016-03-10T19:13:13.550 に答える