如何使用发布参数重定向到外部网址?

问题描述 投票:1回答:1

我正在使用Jhipster应用程序Spring和Angular。我正在尝试执行以下请求:

POST /verifier-2.4.1//webreport HTTP/1.1
Host: verificador.iti.gov.br
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:71.0) Gecko/20100101 Firefox/71.0
Accept: application/json, text/plain, */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: multipart/form-data; boundary=---------------------------118603263816597716931808034283
Content-Length: 3345
Origin: http://localhost:9000
Connection: close
Referer: http://localhost:9000/signature
-----------------------------118603263816597716931808034283
Content-Disposition: form-data; name="signature_text_box0"
ass.p7s
-----------------------------118603263816597716931808034283
Content-Disposition: form-data; name="signature_file"; filename="ass.p7s"
Content-Type: application/pkcs7-mime
<file>

此请求将HTML页面回复为:

HTTP/1.1 200 OK
Date: Fri, 03 Jan 2020 18:14:13 GMT
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=UTF-8
Set-Cookie: JSESSIONID=795451BF2391F9DF8E09E091EA74E426; Path=/verifier-2.4.1/; HttpOnly
Vary: Accept-Encoding
Content-Length: 17247
Connection: close
<!DOCTYPE html>
<html>
...

第一次尝试创建一个调用以下功能的按钮标签:

verifySignature(contentType, field) {
    const data = this.converterToFile(contentType, field);
    const formData = new FormData();
    formData.append('signature_text_box0', 'ass.p7s');
    formData.append('signature_file', data, 'ass.p7s');
    this.http
      .post(`${this.itiVerifierUrl}`, formData)
      .pipe(map((res: HttpResponse<any>) => res.ok))
      .subscribe(
        res => {
          console.log(res);
        },
        (err: HttpErrorResponse) => {
          console.log(err);
        },
      );
  }

按钮标签:

<button class="btn btn-primary btn-sm" type="submit" (click)="verifySignature(signature.encodedContentType, signature.encoded)">
                        <fa-icon [icon]="'check'"></fa-icon>
                        <span class="d-none d-md-inline" jhiTranslate="entity.action.verify">Verify</span>
                      </button>

该请求可以正常运行,但是无法重定向到所需的URL。

第二次尝试创建HTML表单:

<form method="post" action="https://verificador.iti.gov.br/verifier-2.4.1/webreport"
                          target="_blank" enctype="multipart/form-data">
                          <input type="file" value="{{converterToFile(signature.encodedContentType, signature.encoded)}}" name="signature_file">
                          <input type="hidden" name="signature_text_box0" value="ass.p7s">
                          <button class="btn btn-primary btn-sm" type="submit" onclick="submit()">
                            <fa-icon [icon]="'check'"></fa-icon>
                            <span class="d-none d-md-inline" jhiTranslate="entity.action.verify">Verify</span>
                          </button>
                        </form>

这种方式重定向,但不发送文件。请求像这样:

POST /verifier-2.4.1/webreport HTTP/1.1
Host: verificador.iti.gov.br
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:71.0) Gecko/20100101 Firefox/71.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: multipart/form-data; boundary=---------------------------25961331511813356741068188571
Content-Length: 365
Origin: http://localhost:9000
Connection: close
Referer: http://localhost:9000/signature
Cookie: JSESSIONID=7C587222D7D9BD550557E9F3CD60B4FD; __utma=119620560.723777640.1574448373.1577393534.1577465493.3; __utmz=119620560.1577465493.3.3.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided)
Upgrade-Insecure-Requests: 1
-----------------------------25961331511813356741068188571
Content-Disposition: form-data; name="signature_file"; filename=""
Content-Type: application/octet-stream
-----------------------------25961331511813356741068188571
Content-Disposition: form-data; name="signature_text_box0"
ass.p7s
-----------------------------25961331511813356741068188571--

在两种情况下,我都使用此功能将数据转换为文件:

converterToFile(contentType: string, data: string): File {
    const byteCharacters = atob(data);
    const byteNumbers = new Array(byteCharacters.length);
    for (let i = 0; i < byteCharacters.length; i++) {
      byteNumbers[i] = byteCharacters.charCodeAt(i);
    }
    const byteArray = new Uint8Array(byteNumbers);
    return new File([byteArray], 'ass.p7s', {
      type: contentType
    });
  }
angular typescript jhipster
1个回答
0
投票
听起来type = file的输入元素的值不等于文件链接约束。

fileInput.files[0].value = "c:\test.png";

因此,您似乎可以使用隐藏/文本输入或任何json元素,其值是来自任何特殊数据的纯文本,然后服务器会将其作为常规格式数据接收。

hiddenInput.value = "cheers...";

享受!
© www.soinside.com 2019 - 2024. All rights reserved.