首页 > 解决方案 > Alamofire,发布请求 aspx 页面

问题描述

我对编程并不陌生,但我从来没有做过类似的事情,也不是网络抓取方面的专家。

我正在尝试使用 swift 登录我的公司网站。

https://icrew.airmacau.com.mo/Login.aspx

HTML 文件非常简单(从不更改),使用 swiftSoup 我可以解析它并修改登录和密码字段。

在线阅读以便以编程方式登录我应该发出一个帖子请求。

为了使用 Alamofire 发出此帖子请求以取回 html 文件,我应该如何进行?

登录 html 页面有一个带有“Login.aspx”操作的表单

这是我的尝试.. 但老实说,我不确定我应该将什么参数传递给请求,以及是否需要将其他参数传递给发布请求。

func logIn(){
        
        let html = try! String(contentsOf: URL(string: "https://icrew.airmacau.com.mo/Login.aspx")!)
        let doc: Document = try! SwiftSoup.parse(html)
        print("***************")
        
        let username : Element = try! doc.getElementById("userName")!
        print(username)
        let pass : Element = try! doc.getElementById("userPassword")!
        print(pass)
        try! username.append("1234")
        try! pass.append("aassbbcc")
        
        
        //
        let parameter = ["userName":"1234",
                             "userPassword":"aassbbcc"]
        // POST request ....in order to login
        AF.request ("https://icrew.airmacau.com.mo/Login.aspx",method: .post, parameters: parameter).responseString { response in
                print("\(response.result)")
                print(response)
            }
    }

一旦我通过发布请求尝试此代码,我就会打印出与登录页面相同的 html 代码。所以我假设我传递密码和登录的方式是错误的。

谢谢

标签: asp.netswiftweb-scrapinghttp-postalamofire

解决方案


推荐阅读