HTTP Request in Swift with POST method

前端 未结 7 1030
名媛妹妹
名媛妹妹 2020-11-22 05:46

I\'m trying to run a HTTP Request in Swift, to POST 2 parameters to a URL.

Example:

Link: www.thisismylink.com/postName.php

Params:

7条回答
  •  借酒劲吻你
    2020-11-22 06:22

    Heres the method I used in my logging library: https://github.com/goktugyil/QorumLogs

    This method fills html forms inside Google Forms.

        var url = NSURL(string: urlstring)
    
        var request = NSMutableURLRequest(URL: url!)
        request.HTTPMethod = "POST"
        request.setValue("application/x-www-form-urlencoded; charset=utf-8", forHTTPHeaderField: "Content-Type")
        request.HTTPBody = postData.dataUsingEncoding(NSUTF8StringEncoding)
        var connection = NSURLConnection(request: request, delegate: nil, startImmediately: true)
    

提交回复
热议问题