我正在尝试为 POST 请求创建一个 HTTP 实体,该实体看起来像此处列出的 contextIO API 的一部分:
http://context.io/docs/2.0/accounts/messages#post
从他们的文档中,他们给出了以下示例:
POST /2.0/accounts/4f01234567890abcdef09876/messages/ HTTP/1.1
Host: api.context.io
Accept: */*
Authorization: OAuth oauth_consumer_key="abcdef1234",oauth_version="1.0",oauth_timestamp="1327695986",oauth_nonce="6dPrHNDrx5hzfHkn",oauth_signature_method="HMAC-SHA1",oauth_signature="MFOyvf5Ykcsn7une48kGW0Aharw%3D"
Content-Type: multipart/form-data; boundary=------someRandomBoundary
Content-Length: 1917
--------someRandomBoundary
Content-Disposition: form-data; name="dst_folder"
testFolder
--------someRandomBoundary
Content-Disposition: form-data; name="message"; filename="message.eml"
Content-Type: message/rfc822
Delivered-To: jim@bob.com
Received: by 101.42.118.54 with SMTP id hp10cs194007icb;
Thu, 13 Jan 2012 15:02:20 -0700 (PDT)
Return-Path: <blahblahblah@someisp.com>
Received: from [192.168.1.5] (71-211-196-225.hlrn.bob.com. [71.211.196.225])
by mx.bob.com with ESMTPS id u41si888834ybu.20.2011.10.13.14.54.54
(version=TLSv1/SSLv3 cipher=OTHER);
Thu, 13 Jan 2012 15:02:20 -0700 (PDT)
Received: from mail-gx0-f174.someisp.com (mail-gx0-f174.someisp.com [109.45.123.134])
by mx.someisp.com with ESMTPS id u41si888834ybu.20.2011.10.13.14.54.54
(version=TLSv1/SSLv3 cipher=OTHER);
Thu, 13 Jan 2012 14:54:53 -0700 (PDT)
Message-ID: <2E973E2A.3150305@bob.com>
Date: Thu, 13 Jan 2012 15:54:50 -0600
From: Dave Davidson <blahblahblah@someisp.com>
User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.21) Gecko/20110831 Thunderbird/3.1.13
MIME-Version: 1.0
To: Jim Bob <jim@bob.com>
Subject: Just sending out a test message
Content-Type: multipart/alternative;
boundary="------------030009050309030308020807"
This is a multi-part message in MIME format.
--------------030009050309030308020807
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Yo! This is a test multi-part message.
--------------030009050309030308020807
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffff00" text="#ff0000">
Yo! This is a test multi-part message.<br>
</body>
</html>
--------------030009050309030308020807--
--------someRandomBoundary--
我尝试使用以下方法执行此操作:
HttpEntity entity = MultipartEntityBuilder.create()
.addBinaryBody("message", messageSource.getBytes(), ContentType.create("message/rfc822"), "message.eml")
.addTextBody("dst_folder", label)
.addTextBody("dst_source", "0")
.build();
但我似乎无法将整个内容包装在 multipart/form-data 部分中。任何想法如何使用 Apache HTTP 客户端创建此请求?