【问题标题】:ibm mobilefirst post calling between adaptersibm mobilefirst post 适配器之间的调用
【发布时间】:2018-08-22 15:35:04
【问题描述】:

使用 IBM MobileFirst 8.0 平台,我正在探索从其他 Java 适配器端点调用 Java 适配器端点的选项。

IBM 解释的示例(此处)非常简单,并且适用于 GET 方法。简化如下:

String otherAdapterUrlendPoint = "/otherAdapter/endpoint?param="+param;
HttpUriRequest req = new HttpGet(otherAdapterUrlendPoint);
HttpResponse response = adaptersAPI.executeAdapterRequest(req);

这里的问题是 POST 方法(或 PUT 或 DELETE)会发生什么?我没有找到任何文档,也没有找到示例。我虽然可能是这样的:

HttpPost httpPost = new HttpPost(otherAdapterUrlendPoint);
...
<<do something with httpPost object>>
...
HttpUriRequest req = httpPost;
HttpResponse response = adaptersAPI.executeAdapterRequest(req);

但我不确定如何将 json 正文添加到此请求中...(关于标头,我想我可以使用方法 httpPost.addHeader(name, value));

有人可以帮我解决这个疑问吗?我很确定这不是 IBM MobileFirst 主题,而是 Java 主题...

提前致谢!

【问题讨论】:

    标签: java http-post ibm-mobilefirst mobilefirst-server


    【解决方案1】:

    我找到了解决问题的方法。正如我所怀疑的,这不是 IBM MobileFirst 主题,而是 Java 主题。

    这里描述了解决方案:HTTP POST using JSON in Java

    基本上我是这样做的:

    StringEntity postingString = new StringEntity(<<myStringObjectAsJson>>);
    
    String url = "/HTTPJavaAdapter/endPoint";
    HttpPost httpPost = new HttpPost(url);
    httpPost.setEntity(postingString);
    httpPost.setHeader("Content-type", "application/json");
    
    HttpUriRequest req = httpPost;
    adaptersAPI.executeAdapterRequest(req);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-24
      • 1970-01-01
      • 2020-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多