Error consuming restful service POST java in PHP client

1

I have a RestFul service done in java from which I have been able to obtain the list of products that I have registered in the database, but when calling the POST function to insert one, it sends me an error: "The request sent by the client was syntactically incorrect. ", I send a Json array and the code I use in the PHP client is the following:

$proJson=array(
                    "codigoProducto"=>0, 
                    "descripcion"=>$Descripcion, 
                    "descuento"=>$Descuento, 
                    "precio"=>$Precio, 
                    "existenciaMinima"=>$ExistenciaMinima, 
                    "existenciaMaxima"=>$ExistenciaMaxima, 
                    "existencia"=>$Existencia, 
                    "fechaVencimiento"=>$FechaVencimiento, 
                    "activo"=>true, 
                    "codigoCategoria"=>$CodigoCategoria, 
                    "codigoMarca"=>$CodigoMarca, 
                    "codigoProveedor"=>$CodigoProveedor, 
                    "codigoUbicacion"=>$CodigoUbicacion
                );

        $data_string = json_encode($proJson);
        //$data_string=xmlrpc_encode($proJson);
        echo($data_string);
        $ch = curl_init('http://localhost:8080/RestFullParcial2/webresources/com.entidades.tblproducto');
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Content-Type: application/json',
            'Content-Length: ' . strlen($data_string))
        );
        curl_setopt($ch, CURLOPT_TIMEOUT, 5);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);

        //execute post
        $result = curl_exec($ch);

        //close connection
        curl_close($ch);

        echo $result;

I hope you can help me, thanks

    
asked by J.Ochoa 23.10.2017 в 00:13
source

0 answers