从COBOL或CL调用Web服务

时间:2012-12-17 21:39:02

标签: ibm-midrange cobol control-language

我正在使用AS400,并且我被要求从绿屏中调用Web服务。

这怎么能实现呢?

任何样本COBOL或CL代码都会非常有用。

7 个答案:

答案 0 :(得分:5)

我在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以开始使用。

答案 1 :(得分:2)

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

否则,您可以使用HTTPAPI自行推广。同样,我也没有使用它,但我使用了Scott的FTPAPI并且对我有用。

答案 2 :(得分:2)

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

答案 3 :(得分:2)

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

这是一个COBOL示例,它使用libCURL来下载最新的OpenCOBOL预发布版本,使用本地和服务器时间戳来避免任何不当的流量。的 occurlrefresh.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状态代码和消息的小字帖, happenlsym.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的来龙去脉)。的 occurl.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托管。您可能希望更新happenlrefresh.cbl以使用新的默认文件名。此代码现在已经过时了,很快就会获得OpenCOBOL FAQ文件的更新。

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

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

OpenCOBOL示例也适用于CGI和AJAX,libSOUP服务以及一些其他与Web相关的示例。谷歌参与OpenCOBOL常见问题解答,并查看有关扩展的第5部分。调用libXML2也很有魅力。

答案 4 :(得分:1)

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

我们正在使用此技术从IBM i 7.2上的cobol应用程序调用Web服务。

答案 5 :(得分:0)

如果您正在使用Rational Development Studio for i,您应该拥有各种项目类型,您可以在其中为其提供wsdl并让它生成客户端Cobol程序,或者您可以识别副本并让它生成服务器Cobol程序

如果您正在做旧校,1980年的文本编辑器开发,那么您必须自己动手。

答案 6 :(得分:0)

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

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

如果您想了解更多详情,请在上面的链接上找到程序员指南。