gpt4 book ai didi

multipartform-data - wso2 am 网关转发 multipart/form-data post 请求

转载 作者:行者123 更新时间:2023-12-01 16:03:29 27 4
gpt4 key购买 nike

我正在使用一个演示 API,它接收文件和注释作为多部分/表单数据输入并显示文件和注释的内容。这是正确运行 API 的示例 HTML:

<html>   
<body>
<FORM action="http://cgi-lib.berkeley.edu/ex/fup.cgi" method="post">
<P>Choose file: <INPUT type="file" name="upfile">
<p>Note: <INPUT type="text" name="note">
<p><INPUT type="submit" value="Send">
</FORM>
</body>
</html>

现在我正尝试在 WSO2 APIM 发布者中创建一个托管 API。下面是我填写的参数:

enter image description here

我正在替换 HTML 的操作以通过我添加的 API:

<FORM action="http://ec2-52-48-93-41.eu-west-1.compute.amazonaws.com:8280/test" method="post">

但是现在当我运行 HTML 时,我从 API 中收到以下错误:

cgi-lib.pl: Unknown Content-type: application/x-www-form-urlencoded; charset=UTF-8

似乎 WSO2 网关将请求转发为 application/x-www-form-urlencoded 而不是 mulipart/form-data。

基于以下讨论multipart form data file upload using WSO2 API manger ?我试着注释掉

   <messageFormatter contentType="multipart/form-data"
class="org.apache.axis2.transport.http.MultipartFormDataFormatter"/>
<messageBuilder contentType="multipart/form-data"
class="org.apache.axis2.builder.MultipartFormDataBuilder"/>

并将它们替换为

 <messageFormatter contentType="multipart/form-data" 
class="org.wso2.carbon.relay.ExpandingMessageFormatter"/>
<messageBuilder contentType="multipart/form-data"
class="org.wso2.carbon.relay.BinaryRelayBuilder"/>

然后重启了服务器,没有造成任何影响。

任何想法将不胜感激。

我收集的一些日志消息。目标 API 不同,但它也是一个 multipart/form-data API,可以转储它接收到的任何内容。

传入的请求确实有内容类型 multipart/form-data,内容长度为 292

DEBUG {org.apache.synapse.transport.http.headers} -  http-incoming-1 >> POST /test/1.0.0 HTTP/1.1 {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} - http-incoming-1 >> Host: ec2-52-48-93-41.eu-west-1.compute.amazonaws.com:8280 {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} - http-incoming-1 >> Connection: keep-alive {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} - http-incoming-1 >> Content-Length: 292 {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} - http-incoming-1 >> Cache-Control: max-age=0 {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} - http-incoming-1 >> Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} - http-incoming-1 >> Origin: null {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} - http-incoming-1 >> Upgrade-Insecure-Requests: 1 {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} - http-incoming-1 >> User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36 {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} - http-incoming-1 >> Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryqwBdAwOnlDYeHNNR {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} - http-incoming-1 >> Accept-Encoding: gzip, deflate {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} - http-incoming-1 >> Accept-Language: en-US,en;q=0.8,he;q=0.6 {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} - http-incoming-1 >> Cookie: region3_registry_menu=visible; region1_manage_menu=visible; region1_identity_menu=visible; menuPanel=visible; menuPanelType=main; csrftoken=n1g69f3slt1d90qvtaa28rtm1b {org.apache.synapse.transport.http.headers}

传出请求没有内容类型:

DEBUG {org.apache.synapse.transport.http.headers} -  http-outgoing-1 >> POST /sample2/api/company/upload HTTP/1.1 {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} - http-outgoing-1 >> Cookie: region3_registry_menu=visible; region1_manage_menu=visible; region1_identity_menu=visible; menuPanel=visible; menuPanelType=main; csrftoken=n1g69f3slt1d90qvtaa28rtm1b {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} - http-outgoing-1 >> Origin: null {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} - http-outgoing-1 >> Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} - http-outgoing-1 >> Cache-Control: max-age=0 {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} - http-outgoing-1 >> Upgrade-Insecure-Requests: 1 {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} - http-outgoing-1 >> Accept-Encoding: gzip, deflate {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} - http-outgoing-1 >> Accept-Language: en-US,en;q=0.8,he;q=0.6 {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} - http-outgoing-1 >> Transfer-Encoding: chunked {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} - http-outgoing-1 >> Host: localhost:8080 {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} - http-outgoing-1 >> Connection: Keep-Alive {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} - http-outgoing-1 >> User-Agent: Synapse-PT-HttpComponents-NIO {org.apache.synapse.transport.http.headers}

自然地,传入响应具有 HTTP 415,不支持的媒体:

DEBUG {org.apache.synapse.transport.http.headers} -  http-outgoing-1 << HTTP/1.1 415 Unsupported Media Type {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} - http-outgoing-1 << Server: Apache-Coyote/1.1 {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} - http-outgoing-1 << Content-Length: 0 {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} - http-outgoing-1 << Date: Mon, 28 Mar 2016 13:53:05 GMT {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} - http-incoming-1 << HTTP/1.1 415 Unsupported Media Type {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} - http-incoming-1 << Access-Control-Allow-Origin: * {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} - http-incoming-1 << Access-Control-Allow-Methods: POST {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} - http-incoming-1 << Access-Control-Allow-Headers: authorization,Access-Control-Allow-Origin,Content-Type {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} - http-incoming-1 << Date: Mon, 28 Mar 2016 13:53:05 GMT {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} - http-incoming-1 << Transfer-Encoding: chunked {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} - http-incoming-1 << Connection: keep-alive {org.apache.synapse.transport.http.headers}

另外值得加载的是 API 的突触:

<?xml version="1.0" encoding="UTF-8"?>
<api xmlns="http://ws.apache.org/ns/synapse"
name="admin--test"
context="/test/1.0.0"
version="1.0.0"
version-type="context">
<resource methods="POST" url-mapping="/*" faultSequence="fault">
<inSequence>
<filter source="$ctx:AM_KEY_TYPE" regex="PRODUCTION">
<then>
<property name="api.ut.backendRequestTime"
expression="get-property('SYSTEM_TIME')"/>
<send>
<endpoint name="admin--test_APIproductionEndpoint_0">
<http uri-template="http://localhost:8080/sample2/api/company/upload"/>
</endpoint>
</send>
</then>
<else>
<sequence key="_sandbox_key_error_"/>
</else>
</filter>
</inSequence>
<outSequence>
<class name="org.wso2.carbon.apimgt.usage.publisher.APIMgtResponseHandler"/>
<send/>
</outSequence>
</resource>
<handlers>
<handler class="org.wso2.carbon.apimgt.gateway.handlers.security.CORSRequestHandler">
<property name="apiImplementationType" value="ENDPOINT"/>
</handler>
<handler class="org.wso2.carbon.apimgt.gateway.handlers.security.APIAuthenticationHandler"/>
<handler class="org.wso2.carbon.apimgt.gateway.handlers.throttling.APIThrottleHandler">
<property name="policyKey" value="gov:/apimgt/applicationdata/tiers.xml"/>
<property name="policyKeyApplication"
value="gov:/apimgt/applicationdata/app-tiers.xml"/>
<property name="policyKey" value="gov:/apimgt/applicationdata/tiers.xml"/>
<property name="policyKeyApplication"
value="gov:/apimgt/applicationdata/app-tiers.xml"/>
<property name="id" value="A"/>
<property name="policyKeyResource"
value="gov:/apimgt/applicationdata/res-tiers.xml"/>
</handler>
<handler class="org.wso2.carbon.apimgt.usage.publisher.APIMgtUsageHandler"/>
<handler class="org.wso2.carbon.apimgt.usage.publisher.APIMgtGoogleAnalyticsTrackingHandler">
<property name="configKey" value="gov:/apimgt/statistics/ga-config.xml"/>
</handler>
<handler class="org.wso2.carbon.apimgt.gateway.handlers.ext.APIManagerExtensionHandler"/>
</handlers>
</api>

最佳答案

默认情况下,较新的 API 管理器似乎不保留来自客户端的某些 header 。您需要在 repository/conf/passthru-http.properties 中添加以下属性 http.headers.preserve = Content-Type 以保留内容类型 header 。

关于multipartform-data - wso2 am 网关转发 multipart/form-data post 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36258858/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com