使用Webflux实施POST

时间:2019-09-22 22:46:19

标签: java spring spring-boot spring-webflux

我有这个html表单,当我在网络浏览器中打开它时,它运行良好:

pip install -v    
!pip install pyenchant
!pip install pyenchant

我尝试了以下代码:

Enumerating objects: 9, done.
Counting objects: 100% (9/9), done.
Delta compression using up to 4 threads
Compressing objects: 100% (7/7), done.
Writing objects: 100% (9/9), 3.06 KiB | 184.00 KiB/s, done.
Total 9 (delta 0), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote:  !     No default language could be detected for this app.
remote:                         HINT: This occurs when Heroku cannot detect the buildpack to use for this application automatically.
remote:                         See https://devcenter.heroku.com/articles/buildpacks
remote:
remote:  !     Push failed
remote: Verifying deploy...
remote:
remote: !       Push rejected to expensetracker-api-heroku.
remote:
To https://git.heroku.com/expensetracker-api-heroku.git
 ! [remote rejected] secret-branchh -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/expensetracker-api-heroku.git'

但是我收到错误消息:<html> <head> <meta HTTP-EQUIV="Content-Type" content="text/html; charset=UTF-8" /> <meta HTTP-EQUIV="Cache-Control" CONTENT="no cache" /> <meta HTTP-EQUIV="Pragma" CONTENT="no cache" /> <meta HTTP-EQUIV="Expires" CONTENT="0" /> </head> <body OnLoad="AutoSubmitForm();"> <form name="downloadForm" action="https://c3-test.wirecard.com/acssim/app/bank" method="POST"> <input type="hidden" name="PaReq" value="eJxtU9tuozAQ......." /> <input type="hidden" name="TermUrl" value="https://www.test.com" /> <input type="hidden" name="MD" value="optionalValue" /> <SCRIPT LANGUAGE="Javascript"> function AutoSubmitForm() { document.downloadForm.submit();} </SCRIPT> <input type="submit" name="continue" value="Continue" /> </form> </body> </html>

实现此目标的正确方法是什么?

1 个答案:

答案 0 :(得分:1)

您可以尝试这个。

public static <T> T executeApiForFormData(String url, Map<String, String> payload, Map<String, String> headers, Class<T> clazz) {
        WebClient client;
        WebClient.Builder builder = WebClient.builder().baseUrl(url);

        MultiValueMap<String, String> formData = new HttpHeaders();
        formData.setAll(payload);

        if (!ObjectUtils.isEmpty(headers)) {
            MultiValueMap<String, String> map = new HttpHeaders();
            map.setAll(headers);
            builder.defaultHeaders((existingHeaders) -> existingHeaders.addAll(map));
        }


        client = builder.build();

        return client
                .method(HttpMethod.POST)
                .body(BodyInserters.fromFormData(formData))
                .retrieve()
                .bodyToMono(clazz)
                .block();
    }