[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Ftpapi Digest, Vol 118, Issue 9
What we've done for this, is to do a Read Standard in to a stream file, then read that file in to process. See example code:
D QtmhRdStin pr extproc('QtmhRdStin')
D RcvVar * value
D RcvVarLen 10I 0 const
D LenAvail 10I 0
D ErrorCode 32767A options(*varsize)
D getenv PR * extProc('getenv')
D pEnvVar *
/free
// -----------------------------------------------------
// allocate space and read data into user space
// -----------------------------------------------------
monitor;
reqMeth = %str(getenv('REQUEST_METHOD'));
bufsiz = c2n2(%str(getenv('CONTENT_LENGTH')));
buf = %alloc(bufsiz);
QtmhRdStin( buf
: bufsiz
: avail
: FatalError );
on-error;
https = %str(getenv('HTTPS'));
if %trim(reqMeth) <> 'POST';
errMsg = 'Read stdin failed: ' + crlf +
'REQUEST_METHOD = POST required!' + crlf +
'Recvd REQUEST_METHOD: ' + %trim(reqMeth) + crlf +
'Buffer Size: ' + %char(bufsiz) + crlf+
'https: ' + %trim(https) + crlf;
else;
errMsg = 'Read stdin failed: ' + crlf +
'REQUEST_METHOD: ' + %trim(reqMeth) + crlf +
'Buffer Size: ' + %char(bufsiz) + crlf+
'https: ' + %trim(https) + crlf;
endif;
endmon;
// -----------------------------------------------------
// write the received data to a stream file in the IFS
// Since the data is received as EBCDIC, the file is
// Created as EBCDIC (CCSID 37), then written as Text.
// After file is closed, the CCSID must be changed to
// 819 to allow RPG to open the file as Text and read
// the data.
// -----------------------------------------------------
if errMsg = *blanks;
tempfile = '/Redwood'+%str(tmpnam(*omit)) + '.xml';
flags = O_WRONLY+O_CREAT+O_CODEPAGE;
mode = S_IRUSR+S_IWUSR+S_IRGRP+S_IROTH+S_IRGRP;
// Create as EBCDIC file
fd = open( %trim(tempfile)
: flags
: mode
: 37 );
if fd = -1;
p_errno = the_errno();
errMsg = 'open tempfile: '
+ %str(strerror(errno));
else;
callp closef(fd);
// Open and write to file as Text
fd = open(%trim(tempfile):
O_WRONLY+O_TEXTDATA);
if write(fd: buf: avail) < avail;
errMsg = 'write tempfile: '
+ 'Out of space to write entire document!';
endif;
endif;
callp closef(fd);
// Change CCSID to 819 (ASCII) to read file back in
command='CHGATR OBJ('+Tick+%trim(tempfile)+tick+') '+
'ATR(*CCSID) VALUE(819)';
callp(e) qcmdexc(%trim(command):%len(%trim(command)));
dealloc(n) buf;
bufsiz = 0;
endif;
/end-free
-----Original Message-----
From: ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx [mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Dan Dan
Sent: Monday, August 29, 2016 9:34 AM
To: ftpapi@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: Ftpapi Digest, Vol 118, Issue 9
I'm looking for a POST option that will write the response to the IFS (archive) and also allow me to bring the results into memory. Looks like http_url_post_xml would do that for me with one exception in that it tries to parse the response for me and not all of my responses will be XML. Is there a switch/flag something that would tell this process not to parse the response? I received back in the log (SetError() #66: XML parse failed at line 1, col 0: syntax error ).
So move to second option of using _RAW just to get the data back and it looks like it work great and returns the data as I hoped.
Then I get the error "Receiver value too small to hold result. " in Module: HTTPAPIR4 "saveProc". (see below)
I also tried opening a file and pass the FD instead of "1" as I saw in examples but maybe I used wrong options.
fd = open(IFS: O_WRONLY+O_TRUNC+O_CREAT+O_CCSID: 511: 819);
Any help using eithe option would be appreciated.
Thanks,
Dan
rc = http_url_post_raw(%Trim(url)
: %addr(postData) + 2
: %len(PostData)
: 1
: %paddr(Incoming)
: HTTP_TIMEOUT
: HTTP_USERAGENT
: 'Salem05210/SLM');
P Incoming B
D Incoming PI
D descriptor 10I 0 value
D data 8192A options(*varsize)
D datalen 10I 0 value
D TO_ASCII C '1'
D TO_EBCDIC C '2'
/free
rc = http_xlate( datalen
: Data
: TO_EBCDIC );
data = data;
/end-free
P E
Program: HTTPAPIR4 Library: LIBHTTP Module: HTTPAPIR4
4709 4708
4710 4709 c eval rc = saveproc( peFD
4711 4710 c : %addr(wwData)
4712 4711 c : wwLen )
4713 4712
4714 4713 c if HTTP_DEBUG_LEVEL > 1
4715 4714 c callp http_dmsg('recvdoc(): saveproc
4716 4715 c %char(rc) + ' saved')
4717 4716 c endif
4718 4717 c
4719 4718 c if rc < wwLen
4720 4719 c callp SetError(HTTP_RDWERR
More...
Debug . . .
F3=End program F6=Add/Clear breakpoint F10=Step F11=Display variable
F12=Resume F17=Watch variable F18=Work with watch F24=More keys
Receiver value too small to hold result. +
________________________________
-----------------------------------------------------------------------
This is the FTPAPI mailing list. To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------