[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help with HTTP API




Jeffreehy,


Here's what you said you wanted to send:

POST /service.asmx/BuscarClientePorNumeroCliente HTTP/1.1
Host: 200.30.178.70
Content-Type: application/x-www-form-urlencoded
Content-Length: 51

sUsuario=bancon&cClave=banconNumeroDeCliente=2356


Note that the first 5 lines of this data are part of the HTTP protocol. You don't need to supply them to HTTPAPI, it'll insert them for you. That's what HTTPAPI is for, to do that part of the work for you.


The last line is the data you want to send to the server. However, it's only 49 characters long, but you tell me that it's 51 bytes long. It seems like you're missing 2 bytes of data. Looking deeper into your code, I see that in another place, you code the data like this:

sUsuario=bancon&cClave=bancon&iNumeroDeCliente=2356

Host likely, this version is the correct one, because it's the right length, and because iNumeroDeCliente seems like it'd probably be a variable name rather than a value for a variable.

If that's the case, then this is how you should code your program:

H dftactgrp(*no) bnddir('LIBHTTP/HTTPAPI')

/copy libhttp/qrpglesrc,httpapi_h

     D cmd             pr                  extpgm('QCMDEXC')
     D  command                     200A   const
     D  length                       15P 5 const

     D rc              s             10I 0
     D msg             s             52A
     D Enc             s                   like(HTTP_URL_ENCODER)
     D data            s               *
     D size            s             10I 0

/free

*inlr = *on;

        Enc = HTTP_url_encoder_new();
        http_url_encoder_addvar_s( Enc: 'sUsuario': 'bancon');
        http_url_encoder_addvar_s( Enc: 'cClave'  : 'bancon');
        http_url_encoder_addvar_s( Enc: 'iNumeroDeCliente': '2356');

http_url_encoder_getptr(Enc: data: size);

        rc = http_url_post( 'http://200.30.178.70/'
                            +'service.asmx/BuscarClientePorNumeroCliente'
                          : data
                          : size
                          : '/tmp/httptest.html' );

http_url_encoder_free(Enc);

        if (rc <> 1);
            msg = http_error();
            dsply msg;
            return;
        endif;

        cmd('DSPF ''/tmp/httptest.html''': 200);
        return;

/end-free


--- Scott Klement http://www.scottklement.com

On Fri, 10 Feb 2006, Jeffreehy Talavera wrote:

Hi,

I'm trying to acces a Web Service from the iSeries using the HTTPAPI, what I need is to send the following request to the server:


POST /service.asmx/BuscarClientePorNumeroCliente HTTP/1.1 Host: 200.30.178.70 Content-Type: application/x-www-form-urlencoded Content-Length: 51

sUsuario=bancon&cClave=banconNumeroDeCliente=2356


I modified the EXAMPLE4 UPS Tracking to do this, but I'm getin the error :HTTP/1.1 400 Bad Request ( The data is invalid. )

this is the contents of the httpappi_debug file on the Iseries.

Èãã×Á×É@å…™@ñKñóKñ@™…"…¢…„@òððö`ðñ`ðó
%
%ˆ££—m¤™"m—–¢£M]z@…•£…™…„
%ˆ££—m—…™¢‰¢£m–—…•M]z@…•£…™…„
%ˆ££—m"–•‡mׁ™¢…äÙÓM]z@…•£…™…„
%ˆ££—m—…™¢‰¢£m—–¢£M]z@…•£…™…„
%ˆ££—m"–•‡mׁ™¢…äÙÓM]z@…•£…™…„
%„–m—–¢£M]z@…•£…™…„
%×Öâã@a¢…™¥‰ƒ…K¢"§a¤¢ƒ™Ã"‰…•£…×–™Õ¤"…™–Ã"‰…•£…@Èãã×añKñ
%È–¢£z@òððKóðKñ÷øK÷ð
%䢅™`Á‡…•£z@ˆ££—`—‰añKñô
%Ö•£…•£`㨗…z@£…§£a§""
%ŧ—…ƒ£z@ñðð`ƒ–•£‰•¤…
%Ö•£…•£`Ó…•‡£ˆz@õñ
%
%
™…ƒ¥™…¢—M]z@…•£…™…„
%Ⅳř™–™M]@iôóz@Ö""ãÃ×m™…„z@Õ–@ñðð`Ö•£‰•¤…@M…™™–™@‰‡•–™…„]
%¢…•„„–ƒM]z@…•£…™…„
%×Öâã@a¢…™¥‰ƒ…K¢"§a¤¢ƒ™Ã"‰…•£…×–™Õ¤"…™–Ã"‰…•£…@Èã

™…ƒ¥™…¢—M]z@…•£…™…„
%HTTP/1.1 400 Bad Request ( The data is invalid.  )
Via: 1.1 SISTEMATICASPS
Connection: close
Proxy-Connection: close
Pragma: no-cache
Cache-Control: no-cache
Content-Type: text/html
Content-Length: 1946


Ⅳř™–™M]@iñóz@HTTP/1.1 400 Bad Request ( The data is invalid. ) %ˆ££—mƒ"–¢…M]z@…•£…™…„ %



attached is the code that I'm using from the EXAMPLE4,

Thank & Regards,



Jeffr Talavera