doumeilmikv7099 2018-01-09 20:04
浏览 652

在Swift 4中发出HTTP POST请求

I´m trying to send data to a PHP file on my server using URLSession. This seems to fail though, since no data is received on the server. While running the app, I get this console print:

2018-01-09 20:56:10.942359+0100 EinsatzPush[12182:8624757] [BoringSSL] Function boringssl_session_errorlog: line 2871 [boringssl_session_read] SSL_ERROR_ZERO_RETURN(6): operation failed because the connection was cleanly shut down with a close_notify alert
2018-01-09 20:56:10.942857+0100 EinsatzPush[12182:8624757] [BoringSSL] Function boringssl_session_errorlog: line 2871 [boringssl_session_read] SSL_ERROR_ZERO_RETURN(6): operation failed because the connection was cleanly shut down with a close_notify alert
2018-01-09 20:56:10.943028+0100 EinsatzPush[12182:8624757] TIC Read Status [1:0x1c0173680]: 1:57
2018-01-09 20:56:10.943187+0100 EinsatzPush[12182:8624757] TIC Read Status [1:0x1c0173680]: 1:57
2018-01-09 20:56:10.943278+0100 EinsatzPush[12182:8624757] TIC Read Status [1:0x1c0173680]: 1:57
2018-01-09 20:56:10.943923+0100 EinsatzPush[12182:8624757] [BoringSSL] Function boringssl_session_errorlog: line 2871 [boringssl_session_read] SSL_ERROR_ZERO_RETURN(6): operation failed because the connection was cleanly shut down with a close_notify alert

This is the code I´m using:

let url = URL(string: "https://my-server.com/update.php")
    let session = URLSession.shared

    let request = NSMutableURLRequest(url: url as! URL)
    request.httpMethod = "POST"

    let paramString = "username=user&token=token"
    request.httpBody = paramString.data(using: String.Encoding.utf8)

    let task = session.dataTask(with: request as URLRequest) {
        (
        data, response, error) in

        guard let _:NSData = data as NSData?, let _:URLResponse = response, error == nil else {
            print("error")
            return
        }

        if let dataString = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)
        {
            print(dataString)
        }
    }

    task.resume()

I´d be very happy if anyone here could help me get this fixed. Thanks!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!