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

Re: Problem with POST in HTT API



Sender: Christian <chrisv5@xxxxxx>

Well, here is a stripped down version of my program to test the HTTP API with clickatell. If anyone wants to try, one can get a clickatell account in a minute and so, including tne free credits.

PLEASE NOTE: to have the POST work at all, do_post in HTTPAPIR4 *must* be patched to use a 1.0 second timeout for "100 Continue" Otherwise you'll get a timeout with a screwed up HTTP_ERROR().



H DecEdit('0,') DatEdit(*YMD.)
H Option(*SrcStmt:*NoDebugIO)
H DftActGrp(*NO) ActGrp(*NEW)
H BNdDir('LIBHTTP/HTTPAPI')

* Scott Klement's HTTP API
/include LIBHTTP/QRPGLESRC,HTTPAPI_H

D rc              S             10I 0
D Enc             S                   Like(HTTP_URL_ENCODER)

D Request         PR
D   iFunction                   30    Const Varying
D   iEnc                              Like(HTTP_URL_ENCODER)

*#########################################################################
* program interface definition
*#########################################################################
*include QRPGLEH,SMSHTTP
D SMSHTTP         PR
D   iText                      160    Const
D   iPhoneNbr                   20    Const

D SMSHTTP         PI
D   iText                      160    Const
D   iPhoneNbr                   20    Const

*#########################################################################
*  main program
*#########################################################################
/free

Enc=http_url_encoder_new();

 HTTP_URL_Encoder_AddVar_S(Enc : 'api_id'      : '******'        );
 HTTP_URL_Encoder_AddVar_S(Enc : 'user'        : '******'        );
 HTTP_URL_Encoder_AddVar_S(Enc : 'password'    : '********'      );
 HTTP_URL_Encoder_AddVar_S(Enc : 'to'          : %Trim(iPhoneNbr));
 HTTP_URL_Encoder_AddVar_S(Enc : 'from'        : 'HTTP_API'      );
 HTTP_URL_Encoder_AddVar_S(Enc : 'text'        : %Trim(iText)    );

 // to avoid the timeout when using POST, set the timeout for
 // '100 Continue' to 1.0 seconds in do_post
 Request('http/sendmsg':Enc);
 HTTP_URL_Encoder_Free(Enc);

*INLR=*ON;

/end-free

***Request****************************************************************
*  send a request to clickatell
**************************************************************************
P Request         B
D Request         PI
D   iFunction                   30    Const Varying
D   iEnc                              Like(HTTP_URL_ENCODER)

D URL S 32767 Varying

D Data            S               *
D Size            S             10I 0
*-------------------------------------------------------------------------
/free

    // this one works!!
    URL='http://api.clickatell.com/'+iFunction+'?'+
      HTTP_URL_Encoder_GetStr(iENC);
    rc=HTTP_URL_Get(URL:'/result_get.txt');

    // this one fails!!
    HTTP_URL_Encoder_GetPtr(iEnc:Data:Size);
    rc=http_url_post('http://api.clickatell.com/'+iFunction:
        Data:Size:'/result_post.txt');

/end-free
P Request E



----------------------------------------------------------------------- This is the FTPAPI mailing list. To unsubsribe from the list send mail to majordomo@xxxxxxxxxxxxx with the body: unsubscribe ftpapi mymailaddr -----------------------------------------------------------------------