从COBOL或CL调用Web服务



我正在使用AS400,有人要求我从绿色屏幕调用web服务。

这是怎么做到的?

任何示例COBOL或CL代码都将非常有用。

我在RPGLE中编写了一些"中间件"来调用web服务(SOAP)并处理返回的XML数据。简单来说就是这个过程:

1) Open a socket to the web service
2) Build the XML "payload"
3) Transmit the SOAP request (wrap the payload in a SOAP body and transmit the whole through the socket opened in 1) and save the data sent back by the web service.
4) Parse the XML string returned to me (using the xml-sax BIF)
5) Process that data just like any other data.

我用了很多Scott Klement的东西(非常感谢Klement先生!):

ERRNO_H
IFS_H
IFSUTIL_H
SOCKET_H
SOCKUTIL_H

我还必须处理将数据转换为EBCDIC和UTF-8。我想我也模仿了斯科特写的东西,但我记不清了。搜索iconv以开始这方面的工作。

如果您正在寻找简单的东西,可以查看GETURI。我从未亲自使用过它。

否则,您可以使用HTTPAPI自行滚动。同样,我也没有用过这个,但我用过斯科特的FTPAPI,对我来说效果很好

我不是Cobol程序员,但我可以从RPG调用Java。也许您可以用Java编写web服务客户端(这里有很多示例),并从Cobol调用它。

我不是OS/400程序员,但我只是看了一下,libCURL似乎已经移植到了AS/400。

这里有一个COBOL示例,它利用libCURL来降低最新的OpenCOBOL预发布版本,使用本地和服务器时间戳来避免任何不适当的流量发生refresh.cbl

*> **************************************************************
*> * access libcurl to update current OC1.1 source archive
*> **************************************************************
*> Authors:   Brian Tiffin, Joseph James Frantz
*> Dates:     22-July-2008, 29-July-2008
*> Purpose:   Sample calls to occurl wrapper
*>            Wasn't designed to be called a binding
*> Tectonics: cobc -c -Wall occurl.c
*>            cobc -x -lcurl occurlrefresh.cbl occurl.o
*>            ./occurlrefresh [-v|-q] [url file] [-v|-q url file] 
identification division.
program-id. occurlrefresh.
environment division.
input-output section.
data division.
working-storage section.
copy occurlsym.
78 newline     value x"0a".
01 args        pic x(1024).
01 urlarg      pic x(255).
88 urlarg-oc   value
'http://www.sim-basis.de/open-cobol-1.1.tar.gz'.
01 filearg     pic x(255).
88 filearg-oc  value 
'open-cobol-1.1.tar.gz'.
01 verbarg     pic x(255).
01 argcount    pic s9(9) comp-5.
01 verbosity         pic 9(9) usage binary value 1.
88 quiet          value 0.
88 verbose        value 1 thru 2.
88 veryverbose    value 2.
local-storage section.
01 curl        usage pointer.
01 result      pic s9(9) comp-5.
01 curlurl     pic x(256).
01 curlfile    pic x(256).
01 starttime   pic s9(7)v99 comp-5.
01 endtime     pic s9(7)v99 comp-5.
01 showtime    pic z(6)9.99.
01 modtime     usage binary-c-long.
*> Update the OC 1.1 tar if applicable by modification time
procedure division.
*> Pull any command line arguments
accept args from command-line end-accept
unstring args delimited by all spaces
into verbarg urlarg filearg 
tallying in argcount
end-unstring
*> no args is still argcount 1
if verbarg equals spaces
subtract 1 from argcount end-subtract
end-if
evaluate argcount
when 0
set  urlarg-oc  to true
set  filearg-oc to true
when 1
evaluate verbarg
when "-q"  set  quiet       to true
when "-v"  set  veryverbose to true
when other move 1 to verbosity
end-evaluate
set  urlarg-oc  to true
set  filearg-oc to true
when 2
move urlarg     to filearg
move verbarg    to urlarg
when 3
evaluate verbarg
when "-q"  set  quiet       to true
when "-v"  set  veryverbose to true
when other move 1 to verbosity
end-evaluate
end-evaluate
*> null terminate the strings for C
string urlarg    delimited by space
low-value delimited by size
into curlurl
end-string
string filearg   delimited by space
low-value delimited by size
into curlfile
end-string
*> parameters ready
if verbose 
display
"file: " function trim(filearg trailing) 
" from url: " function trim(urlarg trailing) 
end-display
end-if
*> let libcurl do all the hard work
call "occurl_init" returning curl end-call.
*> Set some verbosity options
if verbose
call "occurl_progress" using by value curl
by value verbosity
end-call
end-if
if veryverbose 
call "occurl_verbose" using by value curl
by value verbosity
end-call
end-if
*> move zero to modtime, retrieve_file will test local modtime
move 0 to modtime
accept starttime from time end-accept
call "occurl_retrieve_file" using by value curl
by reference curlurl
by reference curlfile
by reference modtime
returning result
end-call
if verbose
accept endtime from time end-accept
subtract
starttime from endtime giving starttime
end-subtract
divide 
starttime by 100 giving starttime
end-divide
move starttime to showtime
display newline "Done in " showtime end-display
if result not = 0
display
"result: " result
" - " CURLEMSG(result)
end-display
end-if
end-if
call "occurl_cleanup" using by value curl end-call
stop run giving result
continue.
exit program.

加上cURL状态代码和消息的小副本,occuralsym.cpy

*> manifest constants for libcurl
*> Usage: COPY occurlsym  inside data division
*> Result codes
78 CURLE_OK                             VALUE 0.
*> Error codes
78 CURLE_UNSUPPORTED_PROTOCOL           VALUE 1.
78 CURLE_FAILED_INIT                    VALUE 2.
78 CURLE_URL_MALFORMAT                  VALUE 3.
78 CURLE_OBSOLETE4                      VALUE 4.
78 CURLE_COULDNT_RESOLVE_PROXY          VALUE 5.
78 CURLE_COULDNT_RESOLVE_HOST           VALUE 6.
78 CURLE_COULDNT_CONNECT                VALUE 7.
78 CURLE_FTP_WEIRD_SERVER_REPLY         VALUE 8.
78 CURLE_REMOTE_ACCESS_DENIED           VALUE 9.
78 CURLE_OBSOLETE10                     VALUE 10.
78 CURLE_FTP_WEIRD_PASS_REPLY           VALUE 11.
78 CURLE_OBSOLETE12                     VALUE 12.
78 CURLE_FTP_WEIRD_PASV_REPLY           VALUE 13.
78 CURLE_FTP_WEIRD_227_FORMAT           VALUE 14.
78 CURLE_FTP_CANT_GET_HOST              VALUE 15.
78 CURLE_OBSOLETE16                     VALUE 16.
78 CURLE_FTP_COULDNT_SET_TYPE           VALUE 17.
78 CURLE_PARTIAL_FILE                   VALUE 18.
78 CURLE_FTP_COULDNT_RETR_FILE          VALUE 19.
78 CURLE_OBSOLETE20                     VALUE 20.
78 CURLE_QUOTE_ERROR                    VALUE 21.
78 CURLE_HTTP_RETURNED_ERROR            VALUE 22.
78 CURLE_WRITE_ERROR                    VALUE 23.
78 CURLE_OBSOLETE24                     VALUE 24.
78 CURLE_UPLOAD_FAILED                  VALUE 25.
78 CURLE_READ_ERROR                     VALUE 26.
78 CURLE_OUT_OF_MEMORY                  VALUE 27.
78 CURLE_OPERATION_TIMEDOUT             VALUE 28.
78 CURLE_OBSOLETE29                     VALUE 29.
78 CURLE_FTP_PORT_FAILED                VALUE 30.
78 CURLE_FTP_COULDNT_USE_REST           VALUE 31.
78 CURLE_OBSOLETE32                     VALUE 32.
78 CURLE_RANGE_ERROR                    VALUE 33.
78 CURLE_HTTP_POST_ERROR                VALUE 34.
78 CURLE_SSL_CONNECT_ERROR              VALUE 35.
78 CURLE_BAD_DOWNLOAD_RESUME            VALUE 36.
78 CURLE_FILE_COULDNT_READ_FILE         VALUE 37.
78 CURLE_LDAP_CANNOT_BIND               VALUE 38.
78 CURLE_LDAP_SEARCH_FAILED             VALUE 39.
78 CURLE_OBSOLETE40                     VALUE 40.
78 CURLE_FUNCTION_NOT_FOUND             VALUE 41.
78 CURLE_ABORTED_BY_CALLBACK            VALUE 42.
78 CURLE_BAD_FUNCTION_ARGUMENT          VALUE 43.
78 CURLE_OBSOLETE44                     VALUE 44.
78 CURLE_INTERFACE_FAILED               VALUE 45.
78 CURLE_OBSOLETE46                     VALUE 46.
78 CURLE_TOO_MANY_REDIRECTS             VALUE 47.
78 CURLE_UNKNOWN_TELNET_OPTION          VALUE 48.
78 CURLE_TELNET_OPTION_SYNTAX           VALUE 49.
78 CURLE_OBSOLETE50                     VALUE 50.
78 CURLE_PEER_FAILED_VERIFICATION       VALUE 51.
78 CURLE_GOT_NOTHING                    VALUE 52.
78 CURLE_SSL_ENGINE_NOTFOUND            VALUE 53.
78 CURLE_SSL_ENGINE_SETFAILED           VALUE 54.
78 CURLE_SEND_ERROR                     VALUE 55.
78 CURLE_RECV_ERROR                     VALUE 56.
78 CURLE_OBSOLETE57                     VALUE 57.
78 CURLE_SSL_CERTPROBLEM                VALUE 58.
78 CURLE_SSL_CIPHER                     VALUE 59.
78 CURLE_SSL_CACERT                     VALUE 60.
78 CURLE_BAD_CONTENT_ENCODING           VALUE 61.
78 CURLE_LDAP_INVALID_URL               VALUE 62.
78 CURLE_FILESIZE_EXCEEDED              VALUE 63.
78 CURLE_USE_SSL_FAILED                 VALUE 64.
78 CURLE_SEND_FAIL_REWIND               VALUE 65.
78 CURLE_SSL_ENGINE_INITFAILED          VALUE 66.
78 CURLE_LOGIN_DENIED                   VALUE 67.
78 CURLE_TFTP_NOTFOUND                  VALUE 68.
78 CURLE_TFTP_PERM                      VALUE 69.
78 CURLE_REMOTE_DISK_FULL               VALUE 70.
78 CURLE_TFTP_ILLEGAL                   VALUE 71.
78 CURLE_TFTP_UNKNOWNID                 VALUE 72.
78 CURLE_REMOTE_FILE_EXISTS             VALUE 73.
78 CURLE_TFTP_NOSUCHUSER                VALUE 74.
78 CURLE_CONV_FAILED                    VALUE 75.
78 CURLE_CONV_REQD                      VALUE 76.
78 CURLE_SSL_CACERT_BADFILE             VALUE 77.
78 CURLE_REMOTE_FILE_NOT_FOUND          VALUE 78.
78 CURLE_SSH                            VALUE 79.
78 CURLE_SSL_SHUTDOWN_FAILED            VALUE 80.
78 CURLE_AGAIN                          VALUE 81.
*> Error strings
01 LIBCURL_ERRORS.
02 CURLEVALUES.
03 FILLER PIC X(30) VALUE "CURLE_UNSUPPORTED_PROTOCOL    ".
03 FILLER PIC X(30) VALUE "CURLE_FAILED_INIT             ".
03 FILLER PIC X(30) VALUE "CURLE_URL_MALFORMAT           ".
03 FILLER PIC X(30) VALUE "CURLE_OBSOLETE4               ".
03 FILLER PIC X(30) VALUE "CURLE_COULDNT_RESOLVE_PROXY   ".
03 FILLER PIC X(30) VALUE "CURLE_COULDNT_RESOLVE_HOST    ".
03 FILLER PIC X(30) VALUE "CURLE_COULDNT_CONNECT         ".
03 FILLER PIC X(30) VALUE "CURLE_FTP_WEIRD_SERVER_REPLY  ".
03 FILLER PIC X(30) VALUE "CURLE_REMOTE_ACCESS_DENIED    ".
03 FILLER PIC X(30) VALUE "CURLE_OBSOLETE10              ".
03 FILLER PIC X(30) VALUE "CURLE_FTP_WEIRD_PASS_REPLY    ".
03 FILLER PIC X(30) VALUE "CURLE_OBSOLETE12              ".
03 FILLER PIC X(30) VALUE "CURLE_FTP_WEIRD_PASV_REPLY    ".
03 FILLER PIC X(30) VALUE "CURLE_FTP_WEIRD_227_FORMAT    ".
03 FILLER PIC X(30) VALUE "CURLE_FTP_CANT_GET_HOST       ".
03 FILLER PIC X(30) VALUE "CURLE_OBSOLETE16              ".
03 FILLER PIC X(30) VALUE "CURLE_FTP_COULDNT_SET_TYPE    ".
03 FILLER PIC X(30) VALUE "CURLE_PARTIAL_FILE            ".
03 FILLER PIC X(30) VALUE "CURLE_FTP_COULDNT_RETR_FILE   ".
03 FILLER PIC X(30) VALUE "CURLE_OBSOLETE20              ".
03 FILLER PIC X(30) VALUE "CURLE_QUOTE_ERROR             ".
03 FILLER PIC X(30) VALUE "CURLE_HTTP_RETURNED_ERROR     ".
03 FILLER PIC X(30) VALUE "CURLE_WRITE_ERROR             ".
03 FILLER PIC X(30) VALUE "CURLE_OBSOLETE24              ".
03 FILLER PIC X(30) VALUE "CURLE_UPLOAD_FAILED           ".
03 FILLER PIC X(30) VALUE "CURLE_READ_ERROR              ".
03 FILLER PIC X(30) VALUE "CURLE_OUT_OF_MEMORY           ".
03 FILLER PIC X(30) VALUE "CURLE_OPERATION_TIMEDOUT      ".
03 FILLER PIC X(30) VALUE "CURLE_OBSOLETE29              ".
03 FILLER PIC X(30) VALUE "CURLE_FTP_PORT_FAILED         ".
03 FILLER PIC X(30) VALUE "CURLE_FTP_COULDNT_USE_REST    ".
03 FILLER PIC X(30) VALUE "CURLE_OBSOLETE32              ".
03 FILLER PIC X(30) VALUE "CURLE_RANGE_ERROR             ".
03 FILLER PIC X(30) VALUE "CURLE_HTTP_POST_ERROR         ".
03 FILLER PIC X(30) VALUE "CURLE_SSL_CONNECT_ERROR       ".
03 FILLER PIC X(30) VALUE "CURLE_BAD_DOWNLOAD_RESUME     ".
03 FILLER PIC X(30) VALUE "CURLE_FILE_COULDNT_READ_FILE  ".
03 FILLER PIC X(30) VALUE "CURLE_LDAP_CANNOT_BIND        ".
03 FILLER PIC X(30) VALUE "CURLE_LDAP_SEARCH_FAILED      ".
03 FILLER PIC X(30) VALUE "CURLE_OBSOLETE40              ".
03 FILLER PIC X(30) VALUE "CURLE_FUNCTION_NOT_FOUND      ".
03 FILLER PIC X(30) VALUE "CURLE_ABORTED_BY_CALLBACK     ".
03 FILLER PIC X(30) VALUE "CURLE_BAD_FUNCTION_ARGUMENT   ".
03 FILLER PIC X(30) VALUE "CURLE_OBSOLETE44              ".
03 FILLER PIC X(30) VALUE "CURLE_INTERFACE_FAILED        ".
03 FILLER PIC X(30) VALUE "CURLE_OBSOLETE46              ".
03 FILLER PIC X(30) VALUE "CURLE_TOO_MANY_REDIRECTS      ".
03 FILLER PIC X(30) VALUE "CURLE_UNKNOWN_TELNET_OPTION   ".
03 FILLER PIC X(30) VALUE "CURLE_TELNET_OPTION_SYNTAX    ".
03 FILLER PIC X(30) VALUE "CURLE_OBSOLETE50              ".
03 FILLER PIC X(30) VALUE "CURLE_PEER_FAILED_VERIFICATION".
03 FILLER PIC X(30) VALUE "CURLE_GOT_NOTHING             ".
03 FILLER PIC X(30) VALUE "CURLE_SSL_ENGINE_NOTFOUND     ".
03 FILLER PIC X(30) VALUE "CURLE_SSL_ENGINE_SETFAILED    ".
03 FILLER PIC X(30) VALUE "CURLE_SEND_ERROR              ".
03 FILLER PIC X(30) VALUE "CURLE_RECV_ERROR              ".
03 FILLER PIC X(30) VALUE "CURLE_OBSOLETE57              ".
03 FILLER PIC X(30) VALUE "CURLE_SSL_CERTPROBLEM         ".
03 FILLER PIC X(30) VALUE "CURLE_SSL_CIPHER              ".
03 FILLER PIC X(30) VALUE "CURLE_SSL_CACERT              ".
03 FILLER PIC X(30) VALUE "CURLE_BAD_CONTENT_ENCODING    ".
03 FILLER PIC X(30) VALUE "CURLE_LDAP_INVALID_URL        ".
03 FILLER PIC X(30) VALUE "CURLE_FILESIZE_EXCEEDED       ".
03 FILLER PIC X(30) VALUE "CURLE_USE_SSL_FAILED          ".
03 FILLER PIC X(30) VALUE "CURLE_SEND_FAIL_REWIND        ".
03 FILLER PIC X(30) VALUE "CURLE_SSL_ENGINE_INITFAILED   ".
03 FILLER PIC X(30) VALUE "CURLE_LOGIN_DENIED            ".
03 FILLER PIC X(30) VALUE "CURLE_TFTP_NOTFOUND           ".
03 FILLER PIC X(30) VALUE "CURLE_TFTP_PERM               ".
03 FILLER PIC X(30) VALUE "CURLE_REMOTE_DISK_FULL        ".
03 FILLER PIC X(30) VALUE "CURLE_TFTP_ILLEGAL            ".
03 FILLER PIC X(30) VALUE "CURLE_TFTP_UNKNOWNID          ".
03 FILLER PIC X(30) VALUE "CURLE_REMOTE_FILE_EXISTS      ".
03 FILLER PIC X(30) VALUE "CURLE_TFTP_NOSUCHUSER         ".
03 FILLER PIC X(30) VALUE "CURLE_CONV_FAILED             ".
03 FILLER PIC X(30) VALUE "CURLE_CONV_REQD               ".
03 FILLER PIC X(30) VALUE "CURLE_SSL_CACERT_BADFILE      ".
03 FILLER PIC X(30) VALUE "CURLE_REMOTE_FILE_NOT_FOUND   ".
03 FILLER PIC X(30) VALUE "CURLE_SSH                     ".
03 FILLER PIC X(30) VALUE "CURLE_SSL_SHUTDOWN_FAILED     ".
03 FILLER PIC X(30) VALUE "CURLE_AGAIN                   ".
01 FILLER REDEFINES LIBCURL_ERRORS.
02 CURLEMSG OCCURS 81 TIMES PIC X(30).

和一个相关的C文件(尽管很多C可以直接用COBOL编码,因为我在写本文时刚刚学习OpenCOBOL的来龙去脉)发生。c

/**********************************************************************/
/* wrap some common curl operations for use with OpenCOBOL 1.1        */
/* Author:    Brian Tiffin                                            */
/* Date:      21-July-2008                                            */
/* Version:   0.1                                                     */
/* Purpose:   Provide some net access to OpenCOBOL                    */
/* Tectonics: gcc -c occurl.c                                         */
/*            with libcurl dev installed                              */
/**********************************************************************/
#include <stdio.h>
#include <sys/stat.h>
#include <curl/curl.h>
/* Support structure for the file callbacks */
struct LocalFileStruc {
const char *filename;
FILE *stream;
};
/* Progress tracking */
double *Bar;
/* libcurl call back for file write */
static size_t wrap_fwrite(void *buffer, size_t size, size_t nmemb, void *stream) {
struct LocalFileStruc *out=(struct LocalFileStruc *)stream;
if(out && !out->stream) {
/* open file for writing */
out->stream=fopen(out->filename, "wb");
if(!out->stream)
return -1; /* failure, can't open file to write */
}
return fwrite(buffer, size, nmemb, out->stream);
}
/* Progress */
int progress_callback(char *Bar, double t, double d, double ultotal, double ulnow) {
int oe;
double val;
if (t == 0) t = 1.0;
val = d / t * 100;
oe = (int)val;
if (oe & 1) {
putc('\', stdout);
} else {
putc('/', stdout);
}
printf("%03.0f%%bbbbbbbb", val);
fflush(stdout);
return 0;
}
/* Routines to get and release CURL handles from OpenCOBOL */
/* Usage: */
/*   DATA DIVISION. */
/*   01 handle usage is pointer. */
/*   PROCEDURE DIVISION. */
/*   CALL "occurl_init" RETURNING handle. */ 
CURL* occurl_init() {
return curl_easy_init();
}
/* Usage: */
/* CALL "occurl_cleanup" USING BY VALUE handle. */
void occurl_cleanup(CURL *curl) {
curl_easy_cleanup(curl);
}
/* Set verbosity */
/* Usage: vflag being 0 or 1 */
/* CALL "occurl_verbose" USING BY VALUE vflag. */
void occurl_verbose(CURL *curl, int vflag) {
/* Switch on or off full protocol/debug output */
if (curl) {
curl_easy_setopt(curl, CURLOPT_VERBOSE, (long)vflag);
}
}
/* Set progress display on/off */
/* Usage: pflag being 0 or 1 */
/* CALL "occurl_verbose" USING BY VALUE pflag. */
void occurl_progress(CURL *curl, int pflag) {
/* Switch on or off progress display */
if (curl) {
if (pflag) {
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback);
curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &Bar);
} else {
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L);
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, NULL);
curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, NULL);
}
}
}

/* Ease of use; check mod-times, if since then read url, write to file */ 
/* Retrieve URL and save to local file after checking timestamps */
/* Usage: */
/* DATA DIVISION. */
/* 01 handle USAGE IS POINTER. */
/* 01 url. */
/*   02 urlname PIC x(21) VALUE "http://opencobol.org/". */
/*   02 filler  PIC x VALUE X"00". */
/* 01 filename */
/*    02 PIC x(). */
/*    02 filler pic x value low-value. */
/* 01 modtime USAGE IS BINARY-C-LONG */
/* PROCEDURE DIVISION. */
/* CALL "curl_retrieve_file" USING BY VALUE handle */
/*                                 BY REFERENCE url */
/*                                 BY REFERENCE filename */
/*                                 BY REFERENCE modtime */
/*                           RETURNING result. */
/* Pass modtime of 0 to get local mtime field, */
/*   modtime is modified with value from url if available */
int occurl_retrieve_file(CURL *curl, char *url, char *file, long *modtime) {
CURLcode res;
long urlstamp;
struct stat st;
struct LocalFileStruc localfile={
"occurl.default",                 /* default filename */
NULL                              /* stream */
};
/* point to the COBOL passed filename */
if (file) {
localfile.filename = file;
}
/* if modtime is zero, get local file modtime */
if (*modtime == 0) {
if (stat (file, &st) == 0) {
*modtime = st.st_mtime;
}
}
/* let libcurl do all the real work */
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, url);
/* Only fetch new */
curl_easy_setopt(curl, CURLOPT_FILETIME, 1L);
curl_easy_setopt(curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE);
curl_easy_setopt(curl, CURLOPT_TIMEVALUE, *modtime);
/* Define our callback to get called when there's data to be written */
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, wrap_fwrite);
/* Set a pointer to our struct to pass to the callback */
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &localfile);
/* After all the setopts, perform the operation */
res = curl_easy_perform(curl);
/* close off any file pointers */
if (localfile.stream) {
fclose(localfile.stream); /* close the local file */
}
/* return error results */
if (res != 0) {
return (int)res;
}
/* retrieve response code */
res = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &urlstamp);
if (res != 0) {
return (int)res;
} else {
if (urlstamp == 404) {
return CURLE_REMOTE_FILE_NOT_FOUND;
}
}
/* retrieve filetime for return value */
res = curl_easy_getinfo(curl, CURLINFO_FILETIME, &urlstamp);
if (res != 0) {
return (int)res;
} else {
*modtime = urlstamp;
return 0;
}
} else {
return CURLE_FAILED_INIT;
}
return 0;
}
/* Fetch a url to a local file */
int occurl_get_url(CURL *curl, char *theurl, char *thefile) {
CURLcode res;
long urlstamp;
struct LocalFileStruc localfile = {
"occurl.default",         /* default filename */
NULL                      /* stream */
};
/* point to the COBOL field */
localfile.filename = thefile;
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, theurl);
curl_easy_setopt(curl, CURLOPT_FILETIME, 1L);
/* Define our callback to get called when there's data to be written */
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, wrap_fwrite);
/* Set a pointer to our struct to pass to the callback */
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &localfile);
res = curl_easy_perform(curl);
/* close the local file */
if (localfile.stream) {
fclose(localfile.stream);
}
/* return error results */
if (res != 0) {
return (int)res;
}
/* retrieve response code */
res = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &urlstamp);
if (res != 0) {
return (int)res;
} else {
if (urlstamp == 404) {
return CURLE_REMOTE_FILE_NOT_FOUND;
}
}
} else {
return CURLE_FAILED_INIT;
}
return 0;
}
/* The plan is to return a structure with all curl INFO fields filled */
int occurl_getinfo(CURL *curl, char *theurl, char *thedata) {
CURLcode res;
long urlstamp;
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, theurl);
res = curl_easy_getinfo(curl, CURLINFO_FILETIME, &urlstamp);
} else {
return -1;
}
return (int)res;
}

请注意,最近OpenCOBOL领域的情况发生了变化,我们已经转移到SourceForge。1.1 tarball位于http://downloads.sourceforge.net/project/open-cobol/open-cobol/1.1/open-cobol-1.1.tar.gz现在您可能希望更新occurlrefresh.cbl以使用新的默认文件名。这段代码现在很旧,很快就会更新OpenCOBOL FAQ文件。

OpenCOBOL在AS/400上工作,并将二进制文件发布到http://www.kiska.net/opencobol/1.1/这是一台最近从飓风桑迪地下室洪水中恢复的服务器。

当然,您的特定问题需要进行一些修改,使用libCURL将数据拉入WORKING-STORAGE,而不是直接写入文件。

OpenCOBOL示例也适用于CGI和AJAX、libSOUP服务和其他一些与web相关的示例。谷歌查找OpenCOBOL常见问题解答,并浏览关于扩展的第5节。调用libXML2也很有魅力。

IBM在其SYSTOOLS模式中提供对具有SQL用户定义函数的web服务的访问:https://www.ibm.com/developerworks/ibmi/library/i-incorporating-web-service/

我们正在使用这种技术从IBMi7.2上的cobol应用程序中调用web服务。

如果您使用的是Rational Development Studio for i,您应该有各种项目类型,您可以给它一个wsdl并让它生成一个客户端Cobol程序,或者您可以识别一个副本并让它产生一个服务器Cobol程序。

如果你在做老式的、1980年代的文本编辑器开发,那么你就必须自己动手了。

我们研究了在RPG中执行此操作的几个选项。虽然您可以通过字符串连接和打开HTTP端口手动构建SOAP数据包(没错),但我们决定使用一种名为Integrated Web Services for IBM i的IBM技术。

大致的过程是,您将其指向WSDL,它将为您生成一个web服务客户端。这采用了服务程序的形式,然后您可以将其绑定到ILE程序中。

如果你想了解更多细节,上面的链接上有一个程序员指南。

相关内容

  • 没有找到相关文章

最新更新