TransWikia.com

Solicitud URLRequest con parametros POST en Swift 5 Xcode 11.5 iOS a servidor PHP

Stack Overflow en español Asked on November 18, 2021

estoy realizando una petición POST con envío de parámetros utilizando URLSession.shared.dataTask a un servidor PHP. He encontrado varios códigos que hacen solicitud pero este es el único con el que he podido recibir los parámetros en el servidor, pero tengo problemas con la estructura del REQUEST cuando lo recibo en el servidor PHP.

Tengo el siguiente código en swift 5, Xcode 11.5

receiptString es el nombre del parametro String a enviar por POST con un valor largo codificado:

MIIkbgYJKoZIhvcNAQcCoIIkXzCCJFsCAQExCzAJBgUrDgMCGgUAMIIUDwYJKoZIhvcNAQcBoIIUAASCE/wxghP4MAoCAQgCAQEEAhYAMAoCARQCAQEEAgwAMAsCAQECAQEEAwIBADALAgELAgEBBAMCAQAwCwIBDwIBAQQDAgEAMAsCARACAQEEAwIBADALAgEZAgEBBAMCAQMwDAIBAwIBAQQEDAIxMjAMAgEKAgEBBAQWAjQrMAwCAQ4CAQEEBAICAKAwDQIBDQIBAQQFAgMB/cQwDQIBEwIBAQQFDAMxLjAwDgIBCQIBAQQGAgRQMjU1MBgCAQQCAQIEEAN6G7ZARcuOwvuFYrV2wOcwGwIBAAIBAQQTDBFQcm9kdWN0aW9uU2FuZGJveDAcAgEFAgEBBBSdevpCntfZcrI5Z1yHuMqseWXUEjAdAgECAgEBBBUME2NvbS5sbW9udHQuTWlCaWJsaWEwHgIBDAIBAQQWFhQyMDIwLTA3LTE0VDIwOjI5OjAwWjAeAgESAgEBBBYWFDIwMTMtMDgtMDFUMDc6MDA6MDBaMDgCAQcCAQEEMK2K+m4uHjjYSR/G/Tbp5qdggPq1Bq1s0RCl3qgbhMLyO7wK+w3K3iROw/qLqtqDIDBLAgEGAgEBBEMMVP/IVZFu3QRTmuLlTQKuW1suHKmcRf1fejo5L0Sm6Ly5viPpdQOpwoLfBHRy8axTjbbDy6oC0OPZKFx9ddzW+Qk2MIIBfQIBEQIBAQSCAXMxggFvMAsCAgatAgEBBAIMADALAgIGsA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COLNSxkBLYvvRzm+7SZA/LeU802KI++Xj/a8gH7H05g4tTINM4xLG/mk8Ka/8r/FmnBQl8F0BWER5007eLIztHo9VvJOLr0bdw3w9F4SfK8W147ee1Fxeo3H4iNcol1dkP1mvUoiQjEfehrI9zgWDGG1sJL5Ky+ERI8GA4nhX1PSZnIIozavcNgs/e66Mv+VNqW2TAYzN39zoHLFbr2g8hDtq6cxlPtdk2f8GHVdmnmbkyQvvY1XGefqFStxu9k0IkEirHDx22TZxeY8hLgBdQqorV2uT80AkHN7B1dSExggHLMIIBxwIBATCBozCBljELMAkGA1UEBhMCVVMxEzARBgNVBAoMCkFwcGxlIEluYy4xLDAqBgNVBAsMI0FwcGxlIFdvcmxkd2lkZSBEZXZlbG9wZXIgUmVsYXRpb25zMUQwQgYDVQQDDDtBcHBsZSBXb3JsZHdpZGUgRGV2ZWxvcGVyIFJlbGF0aW9ucyBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eQIIDutXh+eeCY0wCQYFKw4DAhoFADANBgkqhkiG9w0BAQEFAASCAQBhSQSJTPCqVFT2KBFjEKM/IaVu1q0t3zSslSci/aHJWT7ZJZTHuFTglP3qvOeT+HxerhuYjAyTFtwgml1Szm54A6+chgaWjKtq0t5Mx9GnYoLn8Am+h5l7njNptzdrvsoUZgq6pWfaxgnDysuzDpQts+0HAwi8n0ZqKoOFEAYricB58RP8E2wgppOeWSQDbAvqAs4JEwej/d5tGWDRJ4xCk7gmKc2HXN6FHvMJuOJlnbWhxJz8SqT6ZRmkKwnSf9KXGpCCeemVXPICI7aaGa+11ZJkSLaZrEHufQXgT7o2qTIwIWd/VjzdRParOKE1kZT8HfHuDZ0pUlL3okGa9YW7

Lo envío de la siguiente forma

        let todosEndpoint: String = "http://192.168.0.59:8888/proyecto/receipt-validation.php"
        guard let todosURL = URL(string: todosEndpoint) else {
            print("===== Error: No se puede crear la URL")
            return
        }
        var request = URLRequest(url: todosURL)
        request.httpMethod = "POST" //Metodo
        let param: [String: Any] = ["parametro": receiptString] //Parametros
        let jsonTodo: Data
        do {
            jsonTodo = try JSONSerialization.data(withJSONObject: param, options: [])
            request.httpBody = jsonTodo
        } catch {
            print("===== Error: No se pudo crear el JSON para enviar al servidor")
            return
        }

        let task = URLSession.shared.dataTask(with: request) { (data, response, error) in
            guard error == nil else {
                print("error calling POST")
                print(error!)
            return
            }
            guard let responseData = data else {
                print("===== Error: No se recibieron datos desde el servidor")
                return
            }

            //Parse the result as JSON, since that's what the API provides
            do {
                guard let receivedTodo = try JSONSerialization.jsonObject(with: responseData, options: []) as? [String: Any] else {
                    print("===== No se pudo obtener JSON de responseData como diccionario")
                    return
                }
                print("=====JSON recibido desde el servidor es: " + receivedTodo.description)

                guard let todoID = receivedTodo["receipt_is_valid"] as? String else {
                    print("===== No se pudo obtener dato receipt_is_valid como String de JSON")
                    return
                }
                print("===== Valor de receipt_is_valid es: (todoID)")
          
            } catch  {
            print("===== Error al analizar responseData de POST en receivedTodo")
            return
            }
        }
        task.resume()

Al imprimir el array del REQUEST cuando lo recibo en el servidor PHP tiene la siguiente estructura. (El valor lo remplazare por algo mas corto)

[15-Jul-2020 03:41:20 UTC] ===== LLEGAMOS A SERVIDOR, REQUEST RECIBIDO: Array
(
    [{"parametro":"MIIkbgYJKoZIhvcNAQcCoIIkXzCCJFsCAQExCzAJBgUrDgMCGgUAMII"}] => 
)

Por lo que cuando intento aplicar un json_decode($_REQUEST); me arroja el siguiente Warning PHP sin obtener el dato.

$param = json_decode($_REQUEST);

[15-Jul-2020 03:41:20 UTC] PHP Warning: json_decode() expects parameter 1 to be string, array given in /Users/asdf/Documents/WorkSpacePhp/proyecto/receipt-validation.php on line 17

Como seria la forma de enviar correctamente el parametro desde swift ?

o

Si esta correctamente enviado como obtengo el valor del parametro si lo recibo con esta estructura en PHP ?

O si conocen alguna otra manera de enviar el parametro por POST que no sea por JSON igual me sirve… intente enviarlo por GET pero no se pudo por que es demasiado largo el dato.

Agradezco su ayuda.

Saludos.

One Answer

Puedes intentar agregando el siguiente header a tu URLRequest :

request.addValue("application/json; charset=UTF-8", forHTTPHeaderField: "Content-Type")

Answered by desaroger on November 18, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP