Sending an HTTP POST request on iOS

前端 未结 7 994
梦谈多话
梦谈多话 2020-11-22 12:04

I\'m trying to send an HTTP Post with the iOS application that I\'m developing but the push never reaches the server although I do get a code 200 as response (from the urlco

7条回答
  •  粉色の甜心
    2020-11-22 12:46

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

    This method fills html forms inside Google Forms. Hope it helps someone using Swift.

    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)
    

提交回复
热议问题