3

简单的问题:

  • 我有一个 webMethods “REST-Service”(_post)。
  • 在“REST-Service”服务中,我称之为自写的 java 服务。
  • 在 java 服务中,我想获取请求的原始正文。

有任何想法吗?

4

1 回答 1

3

根据Content-Type标头,webMethods 选择 aContentHandler来解析输入。原始的身体可以通过这样的 a 保存ContentHandler,但它不是以统一的方式完成的。

示例 1,对于Content-Type: application/x-www-form-urlencoded

InvokeState is = InvokeState.getCurrentState();
byte[] bytesIn = (byte[])is.getPrivateData("$msgBytesIn");
String body = null;
if (bytesIn!=null) {
    body = new String(bytesIn, StandardCharsets.UTF_8);
}
// body now contains the request body

示例 2,对于Content-Type: multipart/form-data

IDataCursor pipelineCursor = pipeline.getCursor();
InputStream bodyStream = (InputStream)IDataUtil.get( pipelineCursor, "contentStream" );
pipelineCursor.destroy();
// bodyStream now contains the request body
于 2015-11-10T16:25:08.407 回答