http_req with POST and large string

Discussions related to HTTPAPI (An HTTP Client Package for RPG programming.) http://www.scottklement.com/httpapi/
belstsrv
Posts: 6
Joined: Tue Jun 20, 2023 7:02 pm

http_req with POST and large string

Post by belstsrv »

Hello,

I am trying to send a large string using http_req but the receiving side is only getting 64K of the string. Using the same string in Postman results in the whole string arriving OK.

My HTTPAPI version is 1.42. My code snippets are below. The large variable is "body" and is defined as shown.

Code: Select all

D body            s        5000000a   varying               

formData = 'req_client='  + %trim(clientcode)   
         + '&req_uri='    + %trim(url)          
         + '&req_method=' + %trim(method)       
         + '&req_body='   + %trim(body);        

http_setOption( 'content-type'                                     
              : 'application/x-www-form-urlencoded' );             
                                                                   
rc = http_req( 'POST'                                              
             : authURL                                             
             : *omit                      // File to receive       
             : response                   // String to receive     
             : *omit                      // File to send          
             : formData );                // String to send        

I am wondering if something with the URL encoded form is causing the data to be truncated?

All variables seem large enough so I am not certain where else to look. I also am not able to see the entirety of the large variable to know for sure if it's OK because STRDBG tops out at 64K to view variables.

I can update to the latest version as well, if needed but was not sure if that was really needed so I did not do that yet.

Anyone have any insights on what I could do to test or what it could be?

Thanks all!
stefan@tageson.se
Posts: 12
Joined: Wed Jul 28, 2021 7:55 am
Location: Viken, Sweden
Contact:

Re: http_req with POST and large string

Post by stefan@tageson.se »

What is the definition of variable formdata?
belstsrv
Posts: 6
Joined: Tue Jun 20, 2023 7:02 pm

Re: http_req with POST and large string

Post by belstsrv »

Code: Select all


** my program **
D formData        s               a   len(16000000) varying 

** HTTPAPI **
D   SendStr                       a   len(16000000) varying const      
D                                     options(*varsize:*omit:*nopass)  
This matches the same variable in the HTTPAPI.
belstsrv
Posts: 6
Joined: Tue Jun 20, 2023 7:02 pm

Re: http_req with POST and large string

Post by belstsrv »

I just updated to the latest version of HTTPAPI and it did not correct the issue.
stefan@tageson.se
Posts: 12
Joined: Wed Jul 28, 2021 7:55 am
Location: Viken, Sweden
Contact:

Re: http_req with POST and large string

Post by stefan@tageson.se »

Any hints from the log file?
belstsrv
Posts: 6
Joined: Tue Jun 20, 2023 7:02 pm

Re: http_req with POST and large string

Post by belstsrv »

Yes, sort of. I had to add logging to this process as we did not have it before. It shows this:

Code: Select all

There are 0 cookies in the cache
POST /m1auth/v9auth.php HTTP/1.1
Host: authhost.domain.com
User-Agent: http-api/1.45
Content-Type: application/x-www-form-urlencoded
Content-Length: 65654
I can also see the payload for the POST is also truncated. I will not post it due to size but the content length from above indicates it's being truncated someplace, just not sure where.

Thank you for your help as well.
User avatar
tools400
Posts: 5
Joined: Thu Jul 29, 2021 4:56 am

Re: http_req with POST and large string

Post by tools400 »

Did you already check the value of SendLen when calling http_persist_req() from http_req()?

And what about wwUplLen when calling do_oper() from http_persist_req().

If these value are correct, I would go further down the chain.
User avatar
tools400
Posts: 5
Joined: Thu Jul 29, 2021 4:56 am

Re: http_req with POST and large string

Post by tools400 »

I would also check the first 4 bytes of field 'body', which contain the length of the field:

eval body:x 4

or

eval body:x 32

if you want to see the first data Bytes, too.
belstsrv
Posts: 6
Joined: Tue Jun 20, 2023 7:02 pm

Re: http_req with POST and large string

Post by belstsrv »

tools400 wrote: Wed Jun 21, 2023 12:58 pm Did you already check the value of SendLen when calling http_persist_req() from http_req()?

And what about wwUplLen when calling do_oper() from http_persist_req().

If these value are correct, I would go further down the chain.
SendLen at the call to http_persist_req() from http_req() is 65654
User avatar
tools400
Posts: 5
Joined: Thu Jul 29, 2021 4:56 am

Re: http_req with POST and large string

Post by tools400 »

So that makes me believe that your "body" field is not at the expected size. It seems that it contains less data than expected. Please double check that.

You may directly check the length bytes of the "body" field after the statement that fills "formData". And you probably want to check the data of the following fields in procedure http_req():
  • SendStr - should match your "formData" field
  • SendPtr - should be the data pointer of field "SendStr"
  • SendLen - should be the length of field "SendStr" (expected: 65654)
Where to set the breakpoint:

Code: Select all

        if sndFd=-1 and %parms >= 6 and %addr(SendStr) <> *null;
           getBufferInfo(SendStr: SendPtr: SendLen );
           sndProc = *null; // add breakpoint and check the values
        endif;
Post Reply