• Publicidad

WWW::Mechanize peticiones GET

Todo lo relacionado con el desarrollo Web con Perl: desde CGI hasta Mojolicious

WWW::Mechanize peticiones GET

Notapor danimera » 2020-01-10 08:11 @382

¿Cómo puedo hacer peticiones a un servicio web usando WWW::Mechanize GET pasándole parámetros?

La documentación dice esto:
Sintáxis: [ Descargar ] [ Ocultar ]
Using text Syntax Highlighting
get() is a well-behaved overloaded version of the method in LWP::UserAgent. This lets you do things like

$mech->get( $uri, ':content_file' => $tempfile );

and you can rest assured that the parms will get filtered down appropriately.
Coloreado en 0.000 segundos, usando GeSHi 1.0.8.4

También vi esto:
Sintáxis: [ Descargar ] [ Ocultar ]
Using text Syntax Highlighting
$ua->get( $url )
$ua->get( $url , $field_name => $value, ... )

This method will dispatch a GET request on the given $url. Further arguments can be given to initialize the headers of the request.
Coloreado en 0.000 segundos, usando GeSHi 1.0.8.4

Pero aun así no me funciona cuando reviso el Webservice; me dice parámetros NULL, pero cuando consumo un método que es con POST sí me funciona bien. Realmente he intentado usar hasta el URI.

Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. my %parameters = (
  2.     key => 'value'
  3. );
  4. my $url = URI->new("http://example.com/i");
  5. $url->query_form(%parameters);
Coloreado en 0.002 segundos, usando GeSHi 1.0.8.4

También tengo este error:

<h1>Software error:</h1>
<pre>Error GETing http://localhost:8585/ws/XXXXX/XXX/vali ... nUsuario=1: Illegal character VCHAR='(' at C:/xampp/cgi-bin/wstest.cgi.pl line 205.
</pre>
100% Telch - Perl Web Programming
Cali PerlMongers: http://cali.pm.org
Avatar de Usuario
danimera
Perlero frecuente
Perlero frecuente
 
Mensajes: 871
Registrado: 2005-06-23 19:02 @834
Ubicación: Colombia

Publicidad

Re: WWW::Mechanize peticiones GET

Notapor explorer » 2020-01-10 09:16 @428

¿Has comprobado en los registros de actividad del servidor web (log) las peticiones GET que está recibiendo?

Es lo primero que haría, para ver si WWW::Mechanize está haciendo bien o mal la petición.
JF^D Perl programming & Raku programming. Grupo en Telegram: https://t.me/Perl_ES
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14476
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España

Re: WWW::Mechanize peticiones GET

Notapor danimera » 2020-01-10 09:20 @430

Sí, claro que sí. Cuando uso un cliente postman o soapui mis parámetros son correctos y los recibe, los puedo imprimir en consola.

Pero con WMechanize Perl, no llega nunca nada, he revisado algunos parámetros en header tipo Transfer-Encoding = chunked en el postman y trato de aplicarlo pero ahora obtengo otros errores...

No he logrado poder hacer llegar los parámetros con Perl, pero sí con PostMan.
100% Telch - Perl Web Programming
Cali PerlMongers: http://cali.pm.org
Avatar de Usuario
danimera
Perlero frecuente
Perlero frecuente
 
Mensajes: 871
Registrado: 2005-06-23 19:02 @834
Ubicación: Colombia

Re: WWW::Mechanize peticiones GET

Notapor danimera » 2020-01-11 10:14 @468

Ya lo pude solucionar. Solo faltaba el json en el parámetro Content:

Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. $mech->get($url, {}, Content => $jsonText);
Coloreado en 0.001 segundos, usando GeSHi 1.0.8.4
100% Telch - Perl Web Programming
Cali PerlMongers: http://cali.pm.org
Avatar de Usuario
danimera
Perlero frecuente
Perlero frecuente
 
Mensajes: 871
Registrado: 2005-06-23 19:02 @834
Ubicación: Colombia


Volver a Web

¿Quién está conectado?

Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 0 invitados