multiple post angular parameters 2/4/5

1

I am working with angular 5 and httpClient, and I have to send 2 objects per post parameter but I do not know how to send them or how to receive them the objects are user1 who has 3 fields user2 who has 3 fields

this is the code in my web api in .net

[HttpPost]
    public bool actualizarUsuario(Usuario oldUser, Usuario newUser)
    {
        try
        {
            return  UsuarioNeg.actualizarUsuario(oldUser, oldUser);
        }
        catch (Exception ex)
        {       
            throw;
        }
    }

and that's how I'm sending it from my service at angular 5

actualizarUsuario(oldUser:any,newUser:any): Observable<any> {
return this.httpClient.post('www.una-url.com', {'oldUser':oldUser , 'newUser':newUser}, this.header);
}

} This is the header:

    this.header = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded', "method": "post" });

Note: Change the url to "www.una-url.cl"

    
asked by Felipe Andres 28.03.2018 в 21:01
source

1 answer

0

In my opinion you still have to say exactly what the problem is ... In first instance to send data by POST with "Content-Type": "application / x-www-form-urlencoded" can not send JSON as you are doing in the previous code.

For "application / x-www-form-urlencoded" the body of the HTTP message sent to the server is essentially a huge string; "The values are encoded in tuples of key values separated by '&', with a '=' between the key and the value." More Details.

Then you must first code to JSON in a valid format of "application / x-www-form-urlencoded"

{'oldUser':oldUser , 'newUser':newUser}
    
answered by 29.03.2018 в 01:57