title: How can I redirect to external url with post parameters?
body: <p>I'm using a Jhipster application, Spring and Angular. I'm trying to do the following request:</p>
  
  <pre><code>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
  &lt;file&gt;
  </code></pre>
  
  <p>This request responds a HTML page as:</p>
  
  <pre><code>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
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  ...
  </code></pre>
  
  <p>The first attempt was creating a button tag that calls the following function:</p>
  
  <pre><code>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&lt;any&gt;) =&gt; res.ok))
        .subscribe(
          res =&gt; {
            console.log(res);
          },
          (err: HttpErrorResponse) =&gt; {
            console.log(err);
          },
        );
    }
  </code></pre>
  
  <p>The button tag: </p>
  
  <pre><code>&lt;button class="btn btn-primary btn-sm" type="submit" (click)="verifySignature(signature.encodedContentType, signature.encoded)"&gt;
                          &lt;fa-icon [icon]="'check'"&gt;&lt;/fa-icon&gt;
                          &lt;span class="d-none d-md-inline" jhiTranslate="entity.action.verify"&gt;Verify&lt;/span&gt;
                        &lt;/button&gt;
  </code></pre>
  
  <p>The request works all right, but it cannot redirect to the desired url.</p>
  
  <p>The second attempt was creating a html form:</p>
  
  <pre><code>&lt;form method="post" action="https://verificador.iti.gov.br/verifier-2.4.1/webreport"
                            target="_blank" enctype="multipart/form-data"&gt;
                            &lt;input type="file" value="{{converterToFile(signature.encodedContentType, signature.encoded)}}" name="signature_file"&gt;
                            &lt;input type="hidden" name="signature_text_box0" value="ass.p7s"&gt;
                            &lt;button class="btn btn-primary btn-sm" type="submit" onclick="submit()"&gt;
                              &lt;fa-icon [icon]="'check'"&gt;&lt;/fa-icon&gt;
                              &lt;span class="d-none d-md-inline" jhiTranslate="entity.action.verify"&gt;Verify&lt;/span&gt;
                            &lt;/button&gt;
                          &lt;/form&gt;
  </code></pre>
  
  <p>This way redirects, but without sending the file. The request went like this:</p>
  
  <pre><code>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--
  </code></pre>
  
  <p>In both cases I'm using this function to convert my data to file:</p>
  
  <pre><code>converterToFile(contentType: string, data: string): File {
      const byteCharacters = atob(data);
      const byteNumbers = new Array(byteCharacters.length);
      for (let i = 0; i &lt; byteCharacters.length; i++) {
        byteNumbers[i] = byteCharacters.charCodeAt(i);
      }
      const byteArray = new Uint8Array(byteNumbers);
      return new File([byteArray], 'ass.p7s', {
        type: contentType
      });
    }
  </code></pre>