简体   繁体   English

将多部分/表单数据Spring Controller传递给外部端点

[英]Pass multipart/form-data Spring Controller to an external endpoint

i have a problem. 我有个问题。 i am trying to proxy pass my form submits to an endpoint that is behind a firewall. 我试图代理传递我的表单提交到防火墙后面的终结点。 Only my Spring Application can access it. 只有我的Spring Application可以访问它。

I want to proxy pass GET and POST request 我想代理传递GET和POST请求

here is an example for my POST request: 这是我的POST请求的示例:

<form action="/proxy/mail" method="post" encType="multipart/form-data">                 
   <input id="file" class="file" type="file" name="file" >
   <input type="text" name="firstname" value="test">
   <input type="submit" value="Submit">
</form>

@RequestMapping("/proxy/**")
@ResponseBody
public String mirrorRest(@RequestBody(required=false) String body, HttpMethod method, HttpServletRequest request, HttpServletResponse response){
    if(!user_is_allowed())){
        return "NO!!!!"
    }

    //TODO: proxy request to http://my-service-behide-firewall/mail
    return result
}

i tried with restTemplate.exchange but had problems with multipart/form-data 我尝试过restTemplate.exchange,但是multipart / form-data有问题

does someone know how to manage this proxy request? 有人知道如何管理此代理请求吗?

refer This Link 参考此链接

In this article, we'll explore the communication between a front-end application and a REST API that are deployed separately. 在本文中,我们将探讨前端应用程序与REST API(分别部署)之间的通信。

The goal is to work around CORS and the Same Origin Policy restriction of the browser and allow the UI to call the API even though they don't share the same origin. 目的是解决CORS和浏览器的“相同来源策略”限制问题,并允许UI调用API,即使它们不共享相同的来源。

We'll basically create two separate applications – a UI application and a simple REST API, and we'll use the Zuul proxy in the UI application to proxy calls to the REST API. 我们基本上将创建两个单独的应用程序-一个UI应用程序和一个简单的REST API,并且将在UI应用程序中使用Zuul代理来代理对REST API的调用。

Zuul is a JVM based router and server side load balancer by Netflix. Zuul是Netflix提供的基于JVM的路由器和服务器端负载平衡器。 And Spring Cloud has a nice integration with an embedded Zuul proxy – which is what we'll use here. 而且,Spring Cloud与嵌入式Zuul代理实现了很好的集成-我们将在这里使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM