1. 获取到HttpClientUtils.jar
  2. 上传到erp服务器

    • cd $TOP/utl/java/jar
    • rz上传jar包
  3. 添加环境变量

    • cd u1/etc
    • vim topenv

      #HttpClientUtils
      CLASSPATH=$TOP/utl/java/jar/HttpClientUtils.jar:$CLASSPATH;export CLASSPATH
    • :wq保存并退出
  4. 重新打开xshell,进入jar文件夹,输入java -jar HttpClientUtils.jar,有输出,则说明正常
  5. 修改T100程序

    • 导入jar包

      IMPORT JAVA HttpClientUtils.HttpClientUtils
      IMPORT JAVA java.util.Hashtable
    • 目前为止该jar包中有6个方法

      • sendGetRequest(String reqURL, String decodeCharset)

        • 参数地址解码字符集
        • 返回值 string类型回传内容

          DEFINE re      STRING
          
          LET re = HttpClientUtils.sendGetRequest("http://172.16.100.42/wstopprd/ws/r/awsp900?WSDL","utf-8")
          DISPLAY re
      • sendGetRequest(String reqURL, Map<String, String> heads, String decodeCharset)

        • 参数地址header解码字符集
        • 返回值 string类型回传内容

          DEFINE re      STRING
          DEFINE heads   Hashtable
          
          LET heads = Hashtable.create()
          CALL heads.put("accept","*/*")
          CALL heads.put("connection","Keep-Alive")
          CALL heads.put("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36")
          LET re = HttpClientUtils.sendGetRequest("http://172.16.100.42/wstopprd/ws/r/awsp900?WSDL",heads,"utf-8")
          DISPLAY re
      • sendPostRequest(String reqURL, Map<String, String> heads, String decodeCharset)

        • 参数地址header解码字符集
        • 返回值 string类型回传报文

          DEFINE re      STRING
          DEFINE heads   Hashtable
          
          LET heads = Hashtable.create()
          CALL heads.put("accept","*/*")
          CALL heads.put("connection","Keep-Alive")
          CALL heads.put("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36")
          LET re = HttpClientUtils.sendPostRequest("http://172.16.100.42/wstopprd/ws/r/awsp920?WSDL",heads,"utf-8")
          DISPLAY re
      • sendPostRequest(String reqURL, Map<String, String> params, String encodeCharset, String decodeCharset)

        • 参数地址params参数编码字符集解码字符集
        • 返回值 string类型回传报文

          DEFINE re      STRING
          DEFINE params  Hashtable
          
          LET params = Hashtable.create()
          CALL params.put("account","admin")
          CALL params.put("password","123456")
          LET re = HttpClientUtils.sendPostRequest("http://172.16.100.42/wstopprd/ws/r/awsp920?WSDL",params,"utf-8","utf-8")
          DISPLAY re
      • sendPostRequest(String reqURL, Map<String, String> heads, Map<String, String> params, String encodeCharset, String decodeCharset)

        • 参数地址headerparams参数编码字符集解码字符集
        • 返回值 string类型回传报文

          DEFINE re      STRING
          DEFINE heads   Hashtable
          DEFINE params  Hashtable
          
          LET heads = Hashtable.create()
          CALL heads.put("accept","*/*")
          CALL heads.put("connection","Keep-Alive")
          CALL heads.put("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36")
          
          LET params = Hashtable.create()
          CALL params.put("account","admin")
          CALL params.put("password","123456")
          LET re = HttpClientUtils.sendPostRequest("http://172.16.100.42/wstopprd/ws/r/awsp920?WSDL",heads,params,"utf-8","utf-8")
          DISPLAY re
      • sendPostByJson(String url, Map<String, String> heads, String body)

        • 参数地址headerjson形态的字符串
        • 返回值 string类型回传报文

          DEFINE re      STRING
          DEFINE heads   Hashtable
          DEFINE body    STRING
          
          LET heads = Hashtable.create()
          CALL heads.put("accept","*/*")
          CALL heads.put("connection","Keep-Alive")
          CALL heads.put("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36")
          LET body = '{"account":"admin","password":"123456"}'
          LET re = HttpClientUtils.sendPostByJson("http://172.16.100.42/wstopprd/ws/r/awsp920?WSDL",heads,body)
          DISPLAY re

此jar包也可以导入其他java工程(例如与加密jar包整合)

END
Last modification:January 12th, 2022 at 12:53 pm
如果觉得我的文章对你有用,请随意赞赏