代码之家  ›  专栏  ›  技术社区  ›  Alex_ES

在适配器之间调用ibm mobilefirst post

  •  0
  • Alex_ES  · 技术社区  · 7 年前

    使用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主体添加到这个请求中。。。(关于标题,我想我可以使用方法 );

    有人能帮我解决这个疑问吗?我敢肯定这不是IBM MobileFirst主题,而是Java主题。。。

    提前谢谢!

    1 回复  |  直到 7 年前
        1
  •  1
  •   Alex_ES    7 年前

    我找到了解决问题的办法。正如我所怀疑的,它不是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);