我正在使用 AS400,我被要求从绿屏调用 Web 服务。
这怎么可能达到?
任何示例 COBOL 或 CL 代码都会非常有帮助。
我正在使用 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 之间的数据转换。我想我也模仿了 Scott 写的一些东西,但我记不清了。搜索 iconv 以开始使用它。
我不是 Cobol 程序员,但我可以从 RPG 调用 Java。也许您可以用 Java 编写 Web 服务客户端(其中有很多示例)并从 Cobol 调用它。
我不是 OS/400 程序员,但我只是看了一下,libCURL 似乎已经移植到了 AS/400。
这是一个 COBOL 示例,它利用 libCURL 来拉取最新的 OpenCOBOL 预发行版,使用本地和服务器时间戳来避免任何不当流量。出现刷新.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.
加上卷曲状态代码和消息的小抄写本,occurrisonsym.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%%\b\b\b\b\b\b\b\b", 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。您可能希望更新发生刷新.cbl 以使用新的默认文件名。这段代码现在很旧,很快就会得到 OpenCOBOL FAQ 文件的更新。
OpenCOBOL 在 AS/400 上运行,二进制文件发布到http://www.kiska.net/opencobol/1.1/,这是最近从飓风桑迪地下室洪水中恢复过来的服务器。
您的特定问题当然需要进行一些修改,利用 libCURL 将数据拉入 WORKING-STORAGE 而不是直接写入文件。
OpenCOBOL 示例还用于 CGI 和 AJAX、libSOUP 服务和其他一些与 Web 相关的示例。Google 获取 OpenCOBOL 常见问题解答并查看第 5 节关于扩展的内容。调用 libXML2 也很有效。
IBM 在其 SYSTOOLS 架构中提供对具有 SQL 用户定义函数的 Web 服务的访问: https ://www.ibm.com/developerworks/ibmi/library/i-incorporating-web-service/
我们正在使用这种技术从 IBM i 7.2 上的 cobol 应用程序调用 Web 服务。
如果您正在使用 Rational Development Studio for i,您应该拥有各种项目类型,您可以在其中给它一个 wsdl 并让它生成一个客户端 Cobol 程序,或者您可以识别一个 copybook 并让它生成一个服务器 Cobol 程序。
如果您正在做老派,1980 年代的文本编辑器开发,那么您必须自己动手。
我们研究了在 RPG 中执行此操作的几个选项。虽然您可以通过字符串连接和打开 HTTP 端口(糟糕)手动构建 SOAP 数据包,但我们决定使用名为Integrated Web Services for IBM i的 IBM 技术。
大致的过程是您将它指向一个 WSDL,它会为您生成一个 Web 服务客户端。这采用服务程序的形式,然后您可以将其绑定到您的 ILE 程序中。
如果您想了解更多详细信息,上面的链接上有一个程序员指南。