如何在Ruby Net中处理多部分http响应:HTTP?

时间:2022-10-24 20:44:15

There is so much information out there on how to generate multipart responses or do multipart file uploads. I can't seem to find any information on how to process a multipart http response. Here is some IRB output from a multipart http response I am working with.

关于如何生成多部分响应或执行多部分文件上传,有很多信息。我似乎无法找到有关如何处理多部分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 

1 个解决方案

#1


0  

You can use Rack to do that for you, here's the utility function that does it: Rack::Utils::parse_multipart. Obviously you'll have to make your response object look like a request object Rack would accept (the env object).

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

#1


0  

You can use Rack to do that for you, here's the utility function that does it: Rack::Utils::parse_multipart. Obviously you'll have to make your response object look like a request object Rack would accept (the env object).

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