5

关于如何生成多部分响应或进行多部分文件上传的信息非常多。我似乎找不到任何有关如何处理多部分 http 响应的信息。这是我正在使用的多部分 http 响应的一些 IRB 输出。

>> response.http.content_type
=> "multipart/related"
>> response.http.body[0..2048]
=> "\r\n------=_Part_3_806633756.1271797659309\r\nContent-Type: text/xml; charset=UTF-8\r\nContent-Transfer-Encoding: binary\r\nContent-Id: <A0FCC4333C6D0FCA346B97FAB6B61818>\r\n\r\n<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><ns1:runReportResponse soapenv:encodingStyle="http://www.w3.org/2003/05/soap-encoding" xmlns:ns1="http://192.168.1.200:8080/jasperserver/services/repository"><ns2:result xmlns:ns2="http://www.w3.org/2003/05/soap-rpc">runReportReturn</ns2:result><runReportReturn xsi:type="xsd:string">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;\n&lt;operationResult version=&quot;2.0.1&quot;&gt;\n\t&lt;returnCode&gt;&lt;![CDATA[0]]&gt;&lt;/returnCode&gt;\n&lt;/operationResult&gt;\n</runReportReturn></ns1:runReportResponse></soapenv:Body></soapenv:Envelope>\r\n------=_Part_3_806633756.1271797659309\r\nContent-Type: application/pdf\r\nContent-Transfer-Encoding: binary\r\nContent-Id: <report>\r\n\r\n%PDF-1.4\n%\342\343\317\323\n3 0 obj 
4

1 回答 1

0

您可以使用 Rack 为您执行此操作,这是执行此操作的实用程序函数:Rack::Utils::parse_multipart。显然,您必须使您的响应对象看起来像 Rack 可以接受的请求对象(env 对象)。

于 2011-01-20T02:22:05.400 回答