我正试图在swift中发送一个http请求 . 我有一个方法( sendHttpRequest ),它将 dictionary<String,AnyObject> 作为参数,并尝试使用php中的一个小服务器向localhost发送请求 . 当我点击调用此功能的按钮时会发生错误

“可选(错误域= NSURLErrorDomain代码= -1002”不支持的URL“UserInfo = {NSErrorFailingURLStringKey = 46.101.145.122 / salvobertoncini.com / servo.php,NSErrorFailingURLKey = 46.101.145.122 / salvobertoncini.com / servo.php,NSLocalizedDescription = unsupported URL,NSUnderlyingError = 0x1763cef0 {错误域= kCFErrorDomainCFNetwork代码= -1002“(null)”}})“

Here is the code:

func sendHttpRequests(data : Dictionary<String, AnyObject>)
{

    let session = NSURLSession.sharedSession()
    do
    {
        let request = try NSJSONSerialization.dataWithJSONObject(data, options: .PrettyPrinted)
        let url = NSURL ( string : "127.0.0.1/Server/servo.php")
        let finalRequest = NSMutableURLRequest(URL: url!)

        finalRequest.HTTPMethod = "POST"
        finalRequest.HTTPBody = request

        let task = session.dataTaskWithRequest(finalRequest){ data,response,error in
            if error != nil
            {
                print("Error -> \(error)")
            }
            do
            {
                let result = try NSJSONSerialization.JSONObjectWithData(data!, options: []) as? [String:AnyObject]
                print("Result -> \(result)")
            }
            catch
            {
                print("Error -> \(error)")
            }
        }
        task.resume()
    }
    catch
    {
        print(error)
    }
}