gpt4 book ai didi

swift - 错误域=NSURLErrorDomain 代码=-1004

转载 作者:行者123 更新时间:2023-11-28 15:30:16 26 4
gpt4 key购买 nike

我是初学者,在手机上部署我的应用程序时遇到问题。该应用程序在模拟器上运行良好,但当我在手机上运行并尝试在手机上发送注册表时,出现以下错误

FAILURE: Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to the server." UserInfo={NSUnderlyingError=0x174244da0 {Error Domain=kCFErrorDomainCFNetwork Code=-1004 "(null)" UserInfo={_kCFStreamErrorCodeKey=61, _kCFStreamErrorDomainKey=1}}, NSErrorFailingURLStringKey=http://localhost/Syafiqah_153046u/register.php, NSErrorFailingURLKey=http://localhost/Syafiqah_153046u/register.php, _kCFStreamErrorDomainKey=1, _kCFStreamErrorCodeKey=61, NSLocalizedDescription=Could not connect to the server.}

下面是我的源代码

class ViewController: UIViewController {
@IBOutlet weak var username: UITextField!
@IBOutlet weak var password: UITextField!
@IBOutlet weak var email: UITextField!
@IBOutlet weak var fullname: UITextField!
@IBOutlet weak var phone: UITextField!
@IBOutlet weak var labelMessage: UILabel!

@IBAction func Register(_ sender: UIButton)
{
let URL_USER_REGISTER = "http://localhost/FYP/register.php"

let parameters: Parameters=[

"username":username.text!,

"password":password.text!,

"email":email.text!,

"fullname":fullname.text!,

"phone":phone.text!

]

//Sending http post request

Alamofire.request(URL_USER_REGISTER, method: .post, parameters: parameters).responseJSON

{
response in

//printing response

print(response)



//getting the json value from the server

if let result = response.result.value

{

//converting it as NSDictionary

let jsonData = result as! NSDictionary

//displaying the message in label

self.labelMessage.text = jsonData.value(forKey: "message") as! String?

}
}
}

override func viewDidLoad()
{
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}

非常感谢您的帮助。谢谢你的时间

最佳答案

从 iPhone 访问本地主机将简单地进行环回/尝试连接到自身(如果它支持的话?)。

您需要做的是找到台式机的 IP(例如,如果是 Windows,请转到命令提示符并键入 ipconfig 或转到网络和共享中心并查找连接状态。

关于swift - 错误域=NSURLErrorDomain 代码=-1004,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44776365/

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