参数“host”在调用中丢失的参数

时间:2021-05-22 09:40:52

Here's my code:

这是我的代码:

func submitLacunaRequest (#module: String, method: String, parameters: AnyObject, completion: (responseObject: AnyObject!, error: NSError!) -> (Void)) -> NSURLSessionTask? {
        let session = NSURLSession.sharedSession()
        let url = NSURL(string: "https://us1.lacunaexpanse.com").URLByAppendingPathComponent(module)
        let request = NSMutableURLRequest(URL: url)
        request.HTTPMethod = "POST"
        request.setValue("application/json-rpc", forHTTPHeaderField: "Content-Type")

Missing argument for parameter "host" in call. It happens at this line.

在调用中缺少参数“host”的参数。它发生在这条线上。

 let url = NSURL(string: "https://us1.lacunaexpanse.com").URLByAppendingPathComponent(module)

Any ideas how to solve this please?

有什么办法可以解决这个问题吗?

Thanks!

谢谢!

1 个解决方案

#1


2  

That eror is missleading. The problem isn't a missing parameter, but how you access the NSURL. You either have to add an ? to access the optional, because the NSURL can be null, or you unwrap it:

eror missleading。问题不是缺少一个参数,而是如何访问NSURL。你要么添加一个?为了访问可选的,因为NSURL可以是空的,或者您打开它:

//First option:
let url = NSURL(string: "https://us1.lacunaexpanse.com")?.URLByAppendingPathComponent(module)

//Unwrapping
if let url = NSURL(string: "https://us1.lacunaexpanse.com")?.URLByAppendingPathComponent(module){
    let request = NSMutableURLRequest(URL: url)
    request.HTTPMethod = "POST"
    request.setValue("application/json-rpc", forHTTPHeaderField: "Content-Type")
}

#1


2  

That eror is missleading. The problem isn't a missing parameter, but how you access the NSURL. You either have to add an ? to access the optional, because the NSURL can be null, or you unwrap it:

eror missleading。问题不是缺少一个参数,而是如何访问NSURL。你要么添加一个?为了访问可选的,因为NSURL可以是空的,或者您打开它:

//First option:
let url = NSURL(string: "https://us1.lacunaexpanse.com")?.URLByAppendingPathComponent(module)

//Unwrapping
if let url = NSURL(string: "https://us1.lacunaexpanse.com")?.URLByAppendingPathComponent(module){
    let request = NSMutableURLRequest(URL: url)
    request.HTTPMethod = "POST"
    request.setValue("application/json-rpc", forHTTPHeaderField: "Content-Type")
}