Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public UsuarioServicio autenticarUsuario(UsuarioServicio usuario)
- {
- try
- {
- var address = new Uri(ConfigurationManager.AppSettings["urlServiciosRestBambu"] + "usuario/servicio");
- var request = WebRequest.Create(address) as HttpWebRequest;
- //Método tipo POST
- request.Method = "POST";
- request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
- var data = new JavaScriptSerializer().Serialize(usuario);
- byte[] byteData = UTF8Encoding.UTF8.GetBytes(data.ToString());
- request.ContentLength = byteData.Length;
- // Escribir los datos
- using (Stream postStream = request.GetRequestStream())
- {
- postStream.Write(byteData, 0, byteData.Length);
- }
- // Obtener la respuesta
- StreamReader reader;
- string result;
- using (var response = request.GetResponse() as HttpWebResponse)
- {
- reader = new StreamReader(response.GetResponseStream());
- result = reader.ReadToEnd();
- }
- log.Info(Resources.Mensajes.msjExitoPeticionRest);
- var javaScriptSerializer = new JavaScriptSerializer();
- UsuarioServicio usuarioAutenticado = javaScriptSerializer.Deserialize<UsuarioServicio>(result);
- return usuarioAutenticado;
- }
- catch (Exception excepcion)
- {
- log.Error(Resources.Mensajes.msjErrorPeticionRest, excepcion);
- throw excepcion;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement