使用rest客户端将excel文件上传到rest服务会导致400错误的请求

问题描述 投票:3回答:2

我有一个用于上传excel文件的休息服务,它可以从UI正常工作,但是我尝试使用RestClient对其有问题的400错误地进行上传

@RequestMapping(value="/{pb}/contents/{contentId}", method=RequestMethod.POST, consumes="multipart/form-data")
    public Long addContent(HttpServletRequest request, @RequestParam("file") MultipartFile file, @PathVariable("pbId") Long pbId, @PathVariable("contentId") Long contentId, @RequestParam(required = false) Map<String, List<? extends Object>> allRequestParameters) throws Exception {
}

要上传的代码

File file = new File("/home/ubx/Desktop/ProductBundle.xlsx");
        byte[] bytez = FileUtils.readFileToByteArray(file);

        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.MULTIPART_FORM_DATA);
        headers.set("Authorization", idToken);

        LinkedMultiValueMap<String, String> pdfHeaderMap = new LinkedMultiValueMap<>();
        pdfHeaderMap.add("Content-disposition", "form-data; name=file; filename=InvalidIsbn.xlsx");
        pdfHeaderMap.add("Content-type", "multipart/form-data");
        HttpEntity<byte[]> doc = new HttpEntity<byte[]>(bytez, pdfHeaderMap);

        LinkedMultiValueMap<String, Object> multipartReqMap = new LinkedMultiValueMap<>();
        multipartReqMap.add("file", doc);

        HttpEntity<LinkedMultiValueMap<String, Object>> reqEntity = new HttpEntity<>(multipartReqMap, headers);


        URI uri = new URI("https://api.mycomp.com/v1/pb/35969258/contents/16828");
        RestTemplate restTemplate = new RestTemplateBuilder().rootUri("https://api.mycomp.com/v1/pb/35969258/contents/16828").build();
        ResponseEntity<String> response = restTemplate.exchange(
                uri, HttpMethod.POST,
                reqEntity, String.class);


        System.out.println("response status: " + response.getStatusCode());
        System.out.println("response body: " + response.getBody());

日志

> 14:12:58.575 [main] DEBUG org.springframework.web.client.RestTemplate
> - HTTP POST https://api.mycomp.com/v1/pb/35969258/contents/16828 14:12:58.591 [main] DEBUG org.springframework.web.client.RestTemplate
> - Accept=[text/plain, application/json, application/cbor, application/*+json, */*] 14:12:58.603 [main] DEBUG
> org.springframework.web.client.RestTemplate - Writing
> [{file=[<[B@55cb6996,[Content-disposition:"form-data; name=file;
> filename=InvalidIsbn.xlsx", Content-type:"multipart/form-data"]>]}] as
> "multipart/form-data" 14:12:58.627 [main] DEBUG
> org.apache.http.client.protocol.RequestAddCookies - CookieSpec
> selected: default 14:12:58.639 [main] DEBUG
> org.apache.http.client.protocol.RequestAuthCache - Auth cache not set
> in the context 14:12:58.640 [main] DEBUG
> org.apache.http.impl.conn.PoolingHttpClientConnectionManager -
> Connection request: [route: {s}->https://api.mycomp.com:443][total
> kept alive: 0; route allocated: 0 of 5; total allocated: 0 of 10]
> 14:12:58.656 [main] DEBUG
> org.apache.http.impl.conn.PoolingHttpClientConnectionManager -
> Connection leased: [id: 0][route:
> {s}->https://api.mycomp.com:443][total kept alive: 0; route allocated:
> 1 of 5; total allocated: 1 of 10] 14:12:58.658 [main] DEBUG
> org.apache.http.impl.execchain.MainClientExec - Opening connection
> {s}->https://api.mycomp.com:443 14:12:59.125 [main] DEBUG
> org.apache.http.impl.conn.DefaultHttpClientConnectionOperator -
> Connecting to api.mycomp.com/10.20.30.40:443 14:12:59.125 [main] DEBUG
> org.apache.http.conn.ssl.SSLConnectionSocketFactory - Connecting
> socket to api.mycomp.com/10.20.30.40:443 with timeout 0 14:12:59.850
> [main] DEBUG org.apache.http.conn.ssl.SSLConnectionSocketFactory -
> Enabled protocols: [TLSv1.3, TLSv1.2, TLSv1.1, TLSv1] 14:12:59.851
> [main] DEBUG org.apache.http.conn.ssl.SSLConnectionSocketFactory -
> Enabled cipher suites:[TLS_AES_128_GCM_SHA256, TLS_AES_256_GCM_SHA384,
> TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
> TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
> TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
> TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA,
> TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA,
> TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
> TLS_DHE_DSS_WITH_AES_128_CBC_SHA, TLS_EMPTY_RENEGOTIATION_INFO_SCSV]
> 14:12:59.851 [main] DEBUG
> org.apache.http.conn.ssl.SSLConnectionSocketFactory - Starting
> handshake 14:13:00.649 [main] DEBUG
> org.apache.http.conn.ssl.SSLConnectionSocketFactory - Secure session
> established 14:13:00.649 [main] DEBUG
> org.apache.http.conn.ssl.SSLConnectionSocketFactory -  negotiated
> protocol: TLSv1.3 14:13:00.649 [main] DEBUG
> org.apache.http.conn.ssl.SSLConnectionSocketFactory -  negotiated
> cipher suite: TLS_AES_128_GCM_SHA256 14:13:00.650 [main] DEBUG
> org.apache.http.conn.ssl.SSLConnectionSocketFactory -  peer principal:
> CN=sni.cloudflaressl.com, O="Cloudflare, Inc.", L=San Francisco,
> ST=CA, C=US 14:13:00.650 [main] DEBUG
> org.apache.http.conn.ssl.SSLConnectionSocketFactory -  peer
> alternative names: [*.mycomp.com, sni.cloudflaressl.com, mycomp.com]
> 14:13:00.650 [main] DEBUG
> org.apache.http.conn.ssl.SSLConnectionSocketFactory -  issuer
> principal: CN=CloudFlare Inc ECC CA-2, O="CloudFlare, Inc.", L=San
> Francisco, ST=CA, C=US 14:13:00.655 [main] DEBUG
> org.apache.http.impl.conn.DefaultHttpClientConnectionOperator -
> Connection established 10.11.12.13:41874<->10.20.30.40:443
> 14:13:00.655 [main] DEBUG
> org.apache.http.impl.execchain.MainClientExec - Executing request POST
> /v1/pb/35969258/contents/16828 HTTP/1.1 14:13:00.655 [main] DEBUG
> org.apache.http.impl.execchain.MainClientExec - Proxy auth state:
> UNCHALLENGED 14:13:00.657 [main] DEBUG org.apache.http.headers -
> http-outgoing-0 >> POST /v1/pb/35969258/contents/16828 HTTP/1.1
> 14:13:00.658 [main] DEBUG org.apache.http.headers - http-outgoing-0 >>
> Accept: text/plain, application/json, application/cbor,
> application/*+json, */* 14:13:00.658 [main] DEBUG
> org.apache.http.headers - http-outgoing-0 >> Content-Type:
> multipart/form-data;charset=UTF-8;boundary=msb9TKKUKLe2QsAH3oli2yu4ha_07J
> 14:13:00.658 [main] DEBUG org.apache.http.headers - http-outgoing-0 >>
> Authorization: idtoken XXXXXXXXXXXX 14:13:00.658 [main] DEBUG
> org.apache.http.headers - http-outgoing-0 >> Content-Length: 3597
> 14:13:00.658 [main] DEBUG org.apache.http.headers - http-outgoing-0 >>
> Host: api.mycomp.com 14:13:00.658 [main] DEBUG org.apache.http.headers
> - http-outgoing-0 >> Connection: Keep-Alive 14:13:00.658 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> User-Agent:
> Apache-HttpClient/4.5.10 (Java/11.0.7) 14:13:00.658 [main] DEBUG
> org.apache.http.headers - http-outgoing-0 >> Accept-Encoding:
> gzip,deflate 14:13:00.658 [main] DEBUG org.apache.http.wire -
> http-outgoing-0 >> "POST /v1/pb/35969258/contents/16828
> HTTP/1.1[\r][\n]" 14:13:00.659 [main] DEBUG org.apache.http.wire -
> http-outgoing-0 >> "Accept: text/plain, application/json,
> application/cbor, application/*+json, */*[\r][\n]" 14:13:00.659 [main]
> DEBUG org.apache.http.wire - http-outgoing-0 >> "Content-Type:
> multipart/form-data;charset=UTF-8;boundary=msb9TKKUKLe2QsAH3oli2yu4ha_07J[\r][\n]"
> 14:13:00.659 [main] DEBUG org.apache.http.wire - http-outgoing-0 >>
> "Authorization: idtoken XXXXXXXXXXXX[\r][\n]" 14:13:00.659 [main]
> DEBUG org.apache.http.wire - http-outgoing-0 >> "Content-Length:
> 3597[\r][\n]" 14:13:00.659 [main] DEBUG org.apache.http.wire -
> http-outgoing-0 >> "Host: api.mycomp.com[\r][\n]" 14:13:00.659 [main]
> DEBUG org.apache.http.wire - http-outgoing-0 >> "Connection:
> Keep-Alive[\r][\n]" 14:13:00.659 [main] DEBUG org.apache.http.wire -
> http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.5.10
> (Java/11.0.7)[\r][\n]" 14:13:00.659 [main] DEBUG org.apache.http.wire
> - http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]" 14:13:00.659 [main] DEBUG org.apache.http.wire - http-outgoing-0 >>
> "[\r][\n]" 14:13:00.659 [main] DEBUG org.apache.http.wire -
> http-outgoing-0 >> "--msb9TKKUKLe2QsAH3oli2yu4ha_07J[\r][\n]"
> 14:13:00.659 [main] DEBUG org.apache.http.wire - http-outgoing-0 >>
> "Content-disposition: form-data; name=file;
> filename=InvalidIsbn.xlsx[\r][\n]" 14:13:00.659 [main] DEBUG
> org.apache.http.wire - http-outgoing-0 >> "Content-type:
> multipart/form-data[\r][\n]" 14:13:00.660 [main] DEBUG
> org.apache.http.wire - http-outgoing-0 >> "Content-Length:
> 3396[\r][\n]" 14:13:00.660 [main] DEBUG org.apache.http.wire -
> http-outgoing-0 >> "[\r][\n]" 14:13:00.660 [main] DEBUG
> org.apache.http.wire - http-outgoing-0 >>
> "PK[0x3][0x4][0x14][0x0][0x8][0x8][0x8][0x0][0x1c][0x89][0xc7]P[0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0xb][0x0][0x0][0x0]_rels/.rels[0xad][0x92][0xc1]j[0xc3]0[0xc][0x86]_[0xc5][0xe8][0xde]8[0xed]`[0x8c]Q[0xb7][0x97]2[0xe8]m[0x8c][0xee][0x1]4[ILb[0xcb][0xd8][0xda][0x96][0xbd][0xfd][0xcc].[K[\n]"
> 14:13:00.660 [main] DEBUG org.apache.http.wire - http-outgoing-0 >>
> "[0x1b][0xec]($}[0xff][0x7][0xd2]v?[0x87]I[0xbd]Q.[0x9e][0xa3][0x81]u[0xd3][0x82][0xa2]h[0xd9][0xf9][0xd8][0x1b]x>=[0xac][0xee]@[0x15][0xc1][0xe8]p[0xe2]H[0x6]"[0xc3]~[0xb7]}[0xa2][0x9][0xa5]n[0x94][0xc1][0xa7][0xa2]*"[0x16][0x3][0x83]H[0xba][0xd7][0xba][0xd8][0x81][0x2][0x96][0x86][0x13][0xc5][0xda][0xe9]8[0x7][0x94]Z[0xe6]^'[0xb4]#[0xf6][0xa4]7m{[0xab][0xf3]O[0x6][0x9c]3[0xd5][0xd1][0x19][0xc8]G[0xb7][0x6]u[0xc2][0xdc][0x93][0x18][0x98]'[0xfd][0xce]y|a[0x1e][0x9b][0x8a][0xad][0x8d][0x8f]D[0xbf][0x9][0xe5][0xae][0xf3][0x96][0xe]l_[0x3]EY[0xc8][0xbe][0x98][0x0][0xbd][0xec][0xb2][0xf9]vql[0x1f]3[0xd7]ML[0xe9][0xbf]eh[0x16][0x8a][0x8e][0xdc]*[0xd5][0x4][0xca][0xe2][0xa9]\3[0xba]Y0[0xb2][0x9c][0xe9]oJ[0xd7][0x8f][0xa2][0x3][0x9]:[0x14][0xfc][0xa2]^[0x8][0xe9][0xb3][0x1f][0xd8]}[0x2]PK[0x7][0x8][0xa7][0x8c]z[0xbd][0xe3][0x0][0x0][0x0]I[0x2][0x0][0x0]PK[0x3][0x4][0x14][0x0][0x8][0x8][0x8][0x0][0x1c][0x89][0xc7]P[0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x13][0x0][0x0][0x0][Content_Types].xml[0xb5]S[0xcb]n[0xc2]0[0x10][0xfc][0x95][0xc8][0xd7]*6[0xf4]PU[0x15][0x81]C[0x1f][0xc7][0x16][0xa9][0xf4][0x3]\{[0x93]X[0xf8]%[0xaf][0xa1][0xf0][0xf7]][0x7]8[0x94]R[0x89][\n]"
> 14:13:00.661 [main] DEBUG org.apache.http.wire - http-outgoing-0 >>
> "q[0xf2]cfgfW[0xf6]d[0xb6]q[0xb6]ZCB[0x13]|[0xc3][0xc6]|[0xc4]*[0xf0]*h[0xe3][0xbb][0x86]},^[0xea]{Va[0x96]^K[0x1b]<4[0xcc][0x7]6[0x9b]N[0x16][0xdb][0x8]XQ[0xa9][0xc7][0x86][0xf5]9[0xc7][0x7]!P[0xf5][0xe0]$[0xf2][0x10][0xc1][0x13][0xd2][0x86][0xe4]d[0xa6]c[0xea]D[0x94]j);[0x10][0xb7][0xa3][0xd1][0x9d]P[0xc1]g[0xf0][0xb9][0xce]E[0x83]M'O[0xd0][0xca][0x95][0xcd][0xd5][0xe3][0xee][0xbe]H7L[0xc6]h[0x8d][0x92][0x99]R[0x89][0xb5][0xd7]G[0xa2][0xf5]^[0x90]'[0xb0][0x3][0x7]{[0x13][0xf1][0x86][0x8][0xac]z[0xde][0x90][0xca][0xae][0x1b]B[0x91][0x89]3[0x1c][0x8e][0xb][0xcb][0x99][0xea][0xde]h.[0xc9]h[0xf8]W[0xb4][0xd0][0xb6]F[0x81][0xe]j[0xe5][0xa8][0x84]CQ[0xd5][0xa0][0xeb][0x98][0x88][0x98][0xb2][0x81]}[0xce][0xb9]L[0xf9]U:[0x12][0x14]D[0x9e][0x13][0x8a][0x82][0xa4][0xf9]%[0xde][0x87][0xb1][0xa8][0x90][0xe0],[0xc3]B[0xbc][0xc8][0xf1][0xa8][[0x8c][0x9][0xa4][0xc6][0x1e]
> ;[0xcb][0xb1][0x97][0x9][0xf4]{N[0xf4][0x98]~[0x87][0xd8]X[0xf1][0x83]p[0xc5][0x1c]ykOL[0xa1][0x4][0x18][0x90]kN[0x80]V[0xee][0xa4][0xf1][0xa7][0xdc][0xbf]BZ~[0x86][0xb0][0xbc][0x9e]q[0x18][0xf6][0xd9][0xf]
> [0x8a]a[0x19][0x1f]r[0x88][0xe1]{O[0xbf][0x1]PK[0x7][0x8]z[0x94][0xca]q;[0x1][0x0][0x0][0x1c][0x4][0x0][0x0]PK[0x3][0x4][0x14][0x0][0x8][0x8][0x8][0x0][0x1c][0x89][0xc7]P[0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x10][0x0][0x0][0x0]docProps/app.xmlM[0x8e][0xc1][\n]"
> 14:13:00.661 [main] DEBUG org.apache.http.wire - http-outgoing-0 >>
> "[0xc2]0[0x10]D[0xef]~E[0xc8][0xbd][0xdd][0xea]AD[0xd2][0x94][0x82][0x8][0x9e][0xec]A?
> [0xa4][0xdb]6[0xd0]lB[0xb2]J?[0xdf][0x9c][0xd4][0xe3][0xcc]0[0x8f][0xa7][0xba][0xcd][0xaf][0xe2][0x8d])[0xbb]@[0xad][0xdc][0xd7][0x8d][0x14]H6[0x8c][0x8e][0xe6]V>[0x1f][0xd7][0xea]$;[0xbd]SC[\n]"
> 14:13:00.661 [main] DEBUG org.apache.http.wire - http-outgoing-0 >>
> "[0x11][0x13];[0xcc][0xa2][0x1c]([0xb7]ra[0x8e]g[0x80]l[0x17][0xf4]&[0xd7]e[0xa6][0xb2]L!y[0xc3]%[0xa6][0x19][0xc2]49[0x8b][0x97]`_[0x1e][0x89][0xe1][0xd0]4G[0xc0][0x8d][0x91]F[0x1c][0xab][0xf8][0x5]J[0xad][0xfa][0x18]Wg[\r][0x17][0x7][0xdd]GS[0x90]b[0xb8][0xdf][0x14][0xfc][0xf7][\n]"
> 14:13:00.661 [main] DEBUG org.apache.http.wire - http-outgoing-0 >>
> "~[0xe][0xfa][0x3]PK[0x7][0x8][0xe1]|w[0xd8][0x91][0x0][0x0][0x0][0xb7][0x0][0x0][0x0]PK[0x3][0x4][0x14][0x0][0x8][0x8][0x8][0x0][0x1c][0x89][0xc7]P[0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x11][0x0][0x0][0x0]docProps/core.xmlm[0x90]]K[0xc3]0[0x14][0x86][0xff]J[0xc8]}[0x9b][0xa4]es[0x84][0xb6]C[0x94][0x81][0xa0]8p[0xe2][0xf0].$[0xc7][0xb6][0xd8]|[0x90]D;[0xff][0xbd]i[0x9d][0x15][0xd4][0xbb]$[0xef]s[0x1e]N[0xde]j{[0xd2][0x3]z[0x7][0x1f]zkj[0xcc]r[0x8a][0x11][0x18]iUo[0xda][0x1a]?[0x1e]v[0xd9][0x6][0xa3][0x10][0x85]Qb[0xb0][0x6]jl,[0xde]6[0x95]t\Z[0xf]{o[0x1d][0xf8][0xd8]C@Ic[0x2][0x97][0xae][0xc6]][0x8c][0x8e][0x13][0x12]d[0x7]Z[0x84]<[0x11]&[0x85]/[0xd6]k[0x11][0xd3][0xd5][0xb7][0xc4][0x9][0xf9]*Z
> [0x5][0xa5]k[0xa2]![\n]" 14:13:00.661 [main] DEBUG
> org.apache.http.wire - http-outgoing-0 >> "%[0xa2]
> [0x93]0s[0x8b][0x11][0x9f][0x95]J.J[0xf7][0xe6][0x87]Y[0xa0]$[0x81][0x1]4[0x98][0x18][0x8][0xcb][0x19][0xf9]a#x[0x1d][0xfe][0x1d][0x98][0x93][0x85]<[0x85]~[0xa1][0xc6]q[0xcc][0xc7]r[0xe6][0xd2]F[0x8c][0x1c][0xef]n[0x1f][0xe6][0xe5][0xb3][0xde]L_[0x97][0x80][0x9b][0xea][0xac][0xe6][0xd2][0x83][0x88][0xa0]P[0x12][0xf0][0xf8][0xe1]R#[0xdf][0xc9]Syu}[0xd8][0xe1][0xa6][0xa0][0x5][0xcd][0xe8]:[0xa3][0x17][0x7][0xc6]x[0xb9][0xe1][0xab][0xd5]sE~[0xcd]O[0xc2][0xaf][0xb3][0xf5][0xcd]e*[0xa4][0x3][0xb4][0xbf][0xbf][0x99][0xb8][0xe5][0xb9]"jn>[0x1]PK[0x7][0x8][0xc5]=G:[0x6][0x1][0x0][0x0][0xb0][0x1][0x0][0x0]PK[0x3][0x4][0x14][0x0][0x8][0x8][0x8][0x0][0x1c][0x89][0xc7]P[0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x14][0x0][0x0][0x0]xl/sharedStrings.xmlu[0x8f]A[\n]"
> 14:13:00.662 [main] DEBUG org.apache.http.wire - http-outgoing-0 >>
> "[0xc2]0[0x14][0x5][0xf7][0x9e]"do[0x93][0xd4][0xd2][0xa6][0x92][0xa6][0xa0]
> [0xb8]q[0xa3][0x1e][0xa0][0xd4]o[0x1b]h[0x92][0x9a][0x9f][0x8a][0xc7][0xb7]"[0xe8]F[0x97]3[0x3][0xf][0x9e][0xaa][0x1f]v
> w[0x8]h[0xbc][0xab][0xa8]H8%[0xe0]Z1[0xae][0xab][0xe8][0xf9][0xb4][JZ[0xeb][0x85]B[0x8c][0xa4][0xf5][0x93][0x8b][0x15][0xcd]([0x99][0x9c][0xb9]M[0xb0][0xfd][0xf0][0xbc][0xe1][0xb0][0xa2]}[0x8c][0xe3][0x9a]1l{[0xb0][\r]&~[0x4]7[0x97][0xab][0xf][0xb6][0x89]3[0x86][0x8e][0xe1][0x18][0xa0][0xb9]`[0xf][0x10][0xed][0xc0]R[0xce]sf[0x1b][0xe3][0xa8]Vh[0xb4][0x8a][0x1a][0xf6][0xc7][0xcd]A[0xb1][0xa8][0x15]{[0x89][0xb7],[0xb])dV[0x16][0x85][0xc8][0xd2][0xf2]o[0xe4]b[0x95][0xfe][0x8a]Y)[0xb].E[0x9e]#[0x9b][0xdf][0xe8]'PK[0x7][0x8][0x9b][0xb5][0xe8][0x8b][0xab][0x0][0x0][0x0][0xfa][0x0][0x0][0x0]PK[0x3][0x4][0x14][0x0][0x8][0x8][0x8][0x0][0x1c][0x89][0xc7]P[0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][\r][0x0][0x0][0x0]xl/styles.xml[0x9d][0x93][0xc1]N[0xc3]0[0xc][0x86][0xef]<E[0x14][0xce],[0xa5]B[0x13]Bmw[0x98]T[0xc4][0x85][0xcb][0x86][0xc4]5k[0xdd]6"q[0xaa]$[0x9d]V[0x9e][0x9e][0xa4])[0xa5];[0x81][0xe8][0xc5][0xce][0x1f][0xfb][0xb3]-[0xa7][0xd9][0xee][0xa2]$9[0x83][0xb1]BcN[0xef]7[0x9]%[0x80][0x95][0xae][0x5][0xb6]9};[0x96]w[0x8f]tW[0xdc]d[0xd6][0x8d][0x12][0xe][0x1d][0x80]#>[0x1]mN;[0xe7][0xfa]'[0xc6]l[0xd5][0x81][0xe2]v[0xa3]{@[0xd3]h[0xa3][0xb8][0xf3]G[0xd3]2[0xdb][0x1b][0xe0][0xb5][\r]IJ[0xb2]4I[0xb6]Lq[0x81][0xb4][0xc8]pP[0xa5]r[0x96]Tz@[0xe7][0xab].[0x12][0x89][0xe6][0xa5][0xf6][0xe2][0xf6][0x81][0x92][0x88][0xdb][0xeb][0x1a]rz[0xbb][0xfe](+26c[0x8a][0xac][0xd1]xM[0xb]B[0x91][0xd9]Or[0xe6][0xd2]+a,[0x9f]Pi[0xa9][\r][0x11]X[0xc3][0x5]|[0x85][0xc7][0xa0]!W[0x10][0xa3][0xf6]\[0x8a][0x93][0x11]Al[0xb8][0x12]r[0x8c]r[0x1a][0x84]i[0xca]9N[0x9][0xd4]f[0xaa][0x1f][0xab]L&4![0xa4]\[0x9a]Hi[0x14][0x8a][0xac][0xe7][0xce][0x81][0xc1][0xd2][0x1f][0xc8][0xec][0x1f][0xc7][0xde][0xcf][0x83][0x1a]!b[0xa6][0xb8]_[0xa2]kn>[0x9e][\r][0x1f]W[0x19][0x93][0xf1][0x85]O[0xda][0xd4]~[0x81][0xeb][0xf9][0xa3]Td[0x12][0x1a][0xe7][0x13][0x8c]h[0xbb]`[0x9d][0xee]Y[0xb8]tN+[0xef][0xd4][0x82][0xb7][0x1a][0xb9][0xc][0xc8][0xef][0x8c][0xd9][0xf1][0xd8][\n]"
> 14:13:00.662 [main] DEBUG org.apache.http.wire - http-outgoing-0 >>
> "[0xa4]<[0x84][0xb5][0xbf]7W[0xec]K[0xb3][0xda]R[0x12]v[0x84][0x8b][0xeb][0x1b][0x9a][0xdd][0x88][0x89][0x87][0xc0]_[0xd3]"{[0x85]M[0xff][0x85]%[0x97]f[0xe1]_e[0xcf]O[0xe7][0xcf][0xf9][0x84][0xf7][0xbd][0x1c]_[0x7]u[0x2]SN/.[0xa7][0xce][0xc][0xb0]4>[0xf5][0xcc]~[0xfe][0x81][0xe2][0xb]PK[0x7][0x8]!l[0xe9][0xd5]r[0x1][0x0][0x0]7[0x3][0x0][0x0]PK[0x3][0x4][0x14][0x0][0x8][0x8][0x8][0x0][0x1c][0x89][0xc7]P[0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0xf][0x0][0x0][0x0]xl/workbook.xml[0x8d][0x8e]AO[0xc3]0[0xc][0x85][0xef][0xfc][0x8a][0xc8]w[0x96]tC[0x8][0xaa][0xa6][0xbb][0xa0]I[0xbb]!1[0xb8]{[0x89][0xbb]Fk[0x92][0xca][0x9][0x1b]?[0x9f][0xb4]S[0x81]#'[0xfb][0xe9]=~[0xcd][0xf6][0xcb][0xf][0xe2]B[0x9c]\[0xc][0x1a][0xaa][0x95][0x2]A[0xc1]D[0xeb][0xc2]I[0xc3][0xfb]aw[0xff][0x4][0xdb][0xf6][0xae][0xb9]F>[0x1f]c<[0x8b][0x12][0xf]IC[0x9f][0xf3]XK[0x99]LO[0x1e][0xd3]*[0x8e][0x14][0x8a][0xd3]E[0xf6][0x98][0x8b][0xe4][0x93]L#[0x13][0xda][0xd4][0x13]e?[0xc8][0xb5]R[0x8f][0xd2][0xa3][0xb]p#[0xd4][0xfc][0x1f]F[0xec]:g[0xe8]%[0x9a]OO![0xdf]
> L[0x3][0xe6]R6[0xf5]nL[0xd0][0xfe]4{ea1S[0xf5][0xac][0x1e]4t8$[0x2][0xd9]6[0x93][0xf3][0xe1][0xe8][0x9a]~[0x83][0x93][0x14]h[0xb2][0xbb][0xd0][0x1][0x8f][0x1a][0xd4][0x94][0x93][0x82]s[0xe7]e[0x8a][0x80][0x9e]4[0xbc]M{[0x5][0x82]kg5[0xf0][0xde]n@[0xcc][0xfe][0xbe][0xc8]j&,gry[0xd4]~[0x3]PK[0x7][0x8][0xb0][0xd9][0xd4][0xea][0xd9][0x0][0x0][0x0]][0x1][0x0][0x0]PK[0x3][0x4][0x14][0x0][0x8][0x8][0x8][0x0][0x1c][0x89][0xc7]P[0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x1a][0x0][0x0][0x0]xl/_rels/workbook.xml.rels[0xad][0x91]Mk[0xc3]0[0xc]@[0xff][0x8a][0xd1]}q[0xd2][0xc1][0x18][0xa3]n/c[0xd0][0xeb][0xd6][0xfd][0x0]c+qh"[0x19]K[0xfb][0xe8][0xbf][0x9f][0xbb][0xc3][0xd6]@[0x7];[0xf4]$[0x8c][0xf0]{[0xf][0xb4][0xde]~[0xce][0x93]y[0xc7]"#[0x93][0x83][0xae]i[0xc1]
> [0x5][0x8e]#[\r][0xe]^[0xf7]O7[0xf7]`D=E?1[0xa1][0x3]b[0xd8]n[0xd6][0xcf]8y[0xad]?$[0x8d]YLE[0x90]8H[0xaa][0xf9][0xc1]Z[0x9][0x9]g/[\r]g[0xa4][0xba][0xe9][0xb9][0xcc]^[0xeb][0xb3][0xc]6[0xfb]p[0xf0][0x3][0xda]U[0xdb][0xde][0xd9]r[0xce][0x80]%[0xd3][0xec][0xa2][0x83][0xb2][0x8b][0x1d][0x98][0xbd]/[0x3][0xaa][0x3]I[0xbe]`|[0xd1]R[0xcb][0xa4][0xa9][0xe0][0xba]:f[0xfc][0x8f][0x96][0xfb]~[0xc][0xf8][0xc8][0xe1]mF[0xd2][0xb]v[0xbb][0x80][0x83][0xbd][0x1c][0xb3]:[0x8b][0xd1][0xe3][0x84][0xd7][0xaf][0xf8][0xa6][0xfe][0xa5][0xbf][0xfd][0xd5]p9HB[0xd4]Sy[0x1d][0xdd][0xb5]K~[0x4][0xa7][0x18][0xbb][0xb8][0xf6][0xe6][0xb]PK[0x7][0x8][0x86][0x3];[0x91][0xd4][0x0][0x0][0x0]3[0x2][0x0][0x0]PK[0x3][0x4][0x14][0x0][0x8][0x8][0x8][0x0][0x1c][0x89][0xc7]P[0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x18][0x0][0x0][0x0]xl/worksheets/sheet1.xmlm[0x92]OO[0xc3]0[0xc][0xc5][0xef]|[0x8a](w[0x96][0xb6][0xdb][0x0]Mm[0xa7]!4[0xc1][0x1][0x9][0xf1][0xef][0x9e][0xb5]n[0x1b][0xad][0x8d][0xab][0xc4][[0xf9][0xf8]8[0x5][\n]"
> 14:13:00.662 [main] DEBUG org.apache.http.wire - http-outgoing-0 >>
> "b;D[0xf2]S[0xde]O[0xcf]v[0x92][0xae]?[0xba]V[0x1c][0xc1]y[0x83]6[0x93][0xf1],[0x92][0x2]l[0x81][0xa5][0xb1]u&[0xdf]^[0xb7][0x97]7r[0x9d]_[0xa4][0x3][0xba][0xbd]o[0x0]H[0xb0][0xdf][0xfa]L6D[0xfd]J)_4[0xd0]i?[0xc3][0x1e],[0xdf]T[0xe8]:M,][0xad]|[0xef]@[0x97]#[0xd4][0xb5]*[0x89][0xa2]+[0xd5]ice[0x9e][0x96][0xa6][0x3][0x1b][0x2][0x85][0x83]*[0x93][0x9b]xu[0xbb][0x90]*OG[0xef][0xbb][0x81][0xc1][0xff][0xa9]E[0x88][0xde]![0xee][0x83]x(3[0xc9][0x1d][0x92][0xde][0xbd]@[0xb][0x5][0x1]kr[0x7][0x8][0xb4]:[0xc1][0xb7]c7ON[0x94]P[0xe9]CK[0xcf]8[0xdc][0x83][0xa9][0x1b][0xe2]A[0x97]<[0xe9]O[0xe4][0x9d]&[0x9d][0xa7][0xe][0x7][0xe1][0xf8][0x86][0x1b],B[0xb1][0x89]9([0x93][0x9e][0xf5]1[0x8f]Ru[0xe4][0x88][0x82][0xf][0xfb]&s2[0x99][0x13])|[0x80][0x91][0xf8]<2[0x9f][0x90][0xf9][0x9][0x92][0x9c]G[0x16][0x13][0xb2]8A[0xe6][0xff][0x10][0xf5]g[0xa2]^[0xd7][0xf0][0xa8]]m[0xac][0x17];$[0xc2][0x8e][0xb7]7[0xbb]^JQ![0x12][0xb8][0xa0][0xb8][0x89][0x86][0x9f]i[0x12]-T4[0xba][0xa4]p_[0xab][0x1a]k[0xc2][0xfe][0x9b][\r][0x9b][0x9e]~C[0xfe][0x9]PK[0x7][0x8]E[0xc6]s[0xa2]1[0x1][0x0][0x0]@[0x2][0x0][0x0]PK[0x1][0x2][0x14][0x0][0x14][0x0][0x8][0x8][0x8][0x0][0x1c][0x89][0xc7]P[0xa7][0x8c]z[0xbd][0xe3][0x0][0x0][0x0]I[0x2][0x0][0x0][0xb][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0]_rels/.relsPK[0x1][0x2][0x14][0x0][0x14][0x0][0x8][0x8][0x8][0x0][0x1c][0x89][0xc7]Pz[0x94][0xca]q;[0x1][0x0][0x0][0x1c][0x4][0x0][0x0][0x13][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x1c][0x1][0x0][0x0][Content_Types].xmlPK[0x1][0x2][0x14][0x0][0x14][0x0][0x8][0x8][0x8][0x0][0x1c][0x89][0xc7]P[0xe1]|w[0xd8][0x91][0x0][0x0][0x0][0xb7][0x0][0x0][0x0][0x10][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x98][0x2][0x0][0x0]docProps/app.xmlPK[0x1][0x2][0x14][0x0][0x14][0x0][0x8][0x8][0x8][0x0][0x1c][0x89][0xc7]P[0xc5]=G:[0x6][0x1][0x0][0x0][0xb0][0x1][0x0][0x0][0x11][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0]g[0x3][0x0][0x0]docProps/core.xmlPK[0x1][0x2][0x14][0x0][0x14][0x0][0x8][0x8][0x8][0x0][0x1c][0x89][0xc7]P[0x9b][0xb5][0xe8][0x8b][0xab][0x0][0x0][0x0][0xfa][0x0][0x0][0x0][0x14][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0xac][0x4][0x0][0x0]xl/sharedStrings.xmlPK[0x1][0x2][0x14][0x0][0x14][0x0][0x8][0x8][0x8][0x0][0x1c][0x89][0xc7]P!l[0xe9][0xd5]r[0x1][0x0][0x0]7[0x3][0x0][0x0][\r][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x99][0x5][0x0][0x0]xl/styles.xmlPK[0x1][0x2][0x14][0x0][0x14][0x0][0x8][0x8][0x8][0x0][0x1c][0x89][0xc7]P[0xb0][0xd9][0xd4][0xea][0xd9][0x0][0x0][0x0]][0x1][0x0][0x0][0xf][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0]F[0x7][0x0][0x0]xl/workbook.xmlPK[0x1][0x2][0x14][0x0][0x14][0x0][0x8][0x8][0x8][0x0][0x1c][0x89][0xc7]P[0x86][0x3];[0x91][0xd4][0x0][0x0][0x0]3[0x2][0x0][0x0][0x1a][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0]\[0x8][0x0][0x0]xl/_rels/workbook.xml.relsPK[0x1][0x2][0x14][0x0][0x14][0x0][0x8][0x8][0x8][0x0][0x1c][0x89][0xc7]PE[0xc6]s[0xa2]1[0x1][0x0][0x0]@[0x2][0x0][0x0][0x18][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0]x[0x9][0x0][0x0]xl/worksheets/sheet1.xmlPK[0x5][0x6][0x0][0x0][0x0][0x0][0x9][0x0][0x9][0x0]?[0x2][0x0][0x0][0xef][\n]"
> 14:13:00.662 [main] DEBUG org.apache.http.wire - http-outgoing-0 >>
> "[0x0][0x0][0x0][0x0][\r][\n]" 14:13:00.663 [main] DEBUG
> org.apache.http.wire - http-outgoing-0 >>
> "--msb9TKKUKLe2QsAH3oli2yu4ha_07J--[\r][\n]" 14:13:01.430 [main] DEBUG
> org.apache.http.wire - http-outgoing-0 << "HTTP/1.1 400 [\r][\n]"
> 14:13:01.431 [main] DEBUG org.apache.http.wire - http-outgoing-0 <<
> "Date: Mon, 08 Jun 2020 08:43:01 GMT[\r][\n]" 14:13:01.431 [main]
> DEBUG org.apache.http.wire - http-outgoing-0 << "Content-Type:
> application/json;charset=UTF-8[\r][\n]" 14:13:01.431 [main] DEBUG
> org.apache.http.wire - http-outgoing-0 << "Content-Length:
> 218[\r][\n]" 14:13:01.431 [main] DEBUG org.apache.http.wire -
> http-outgoing-0 << "Connection: keep-alive[\r][\n]" 14:13:01.431
> [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Set-Cookie:
> __cfduid=dae179e337900149671fe646ba45be8551591605780; expires=Wed, 08-Jul-20 08:43:00 GMT; path=/; domain=.mycomp.com; HttpOnly;
> SameSite=Lax; Secure[\r][\n]" 14:13:01.431 [main] DEBUG
> org.apache.http.wire - http-outgoing-0 <<
> "Access-Control-Allow-Credentials: true[\r][\n]" 14:13:01.431 [main]
> DEBUG org.apache.http.wire - http-outgoing-0 <<
> "Access-Control-Allow-Methods:
> GET,POST,PUT,DELETE,OPTIONS,PATCH[\r][\n]" 14:13:01.431 [main] DEBUG
> org.apache.http.wire - http-outgoing-0 << "CF-Cache-Status:
> DYNAMIC[\r][\n]" 14:13:01.431 [main] DEBUG org.apache.http.wire -
> http-outgoing-0 << "cf-request-id:
> 0334b1f9dc000073f98a82e200000001[\r][\n]" 14:13:01.431 [main] DEBUG
> org.apache.http.wire - http-outgoing-0 << "Expect-CT: max-age=604800,
> report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"[\r][\n]" 14:13:01.432 [main] DEBUG org.apache.http.wire - http-outgoing-0 <<
> "Server: cloudflare[\r][\n]" 14:13:01.432 [main] DEBUG
> org.apache.http.wire - http-outgoing-0 << "CF-RAY:
> 5a0152a2fd3d73f9-IAD[\r][\n]" 14:13:01.432 [main] DEBUG
> org.apache.http.wire - http-outgoing-0 << "[\r][\n]" 14:13:01.432
> [main] DEBUG org.apache.http.wire - http-outgoing-0 <<
> "{"id":"8bcc1231-444f-4795-a142-fe0d5c788bb4","timeStamp":"2020.06.08.08.43.01.289","requestURL":"http://api.mycomp.com/pb/35969258/contents/16828","requestMethod":"POST","error":"Bad
> Request"}" 14:13:01.437 [main] DEBUG org.apache.http.headers -
> http-outgoing-0 << HTTP/1.1 400  14:13:01.438 [main] DEBUG
> org.apache.http.headers - http-outgoing-0 << Date: Mon, 08 Jun 2020
> 08:43:01 GMT 14:13:01.438 [main] DEBUG org.apache.http.headers -
> http-outgoing-0 << Content-Type: application/json;charset=UTF-8
> 14:13:01.438 [main] DEBUG org.apache.http.headers - http-outgoing-0 <<
> Content-Length: 218 14:13:01.438 [main] DEBUG org.apache.http.headers
> - http-outgoing-0 << Connection: keep-alive 14:13:01.438 [main] DEBUG org.apache.http.headers - http-outgoing-0 << Set-Cookie:
> __cfduid=dae179e337900149671fe646ba45be8551591605780; expires=Wed, 08-Jul-20 08:43:00 GMT; path=/; domain=.mycomp.com; HttpOnly;
> SameSite=Lax; Secure 14:13:01.438 [main] DEBUG org.apache.http.headers
> - http-outgoing-0 << Access-Control-Allow-Credentials: true 14:13:01.438 [main] DEBUG org.apache.http.headers - http-outgoing-0 <<
> Access-Control-Allow-Methods: GET,POST,PUT,DELETE,OPTIONS,PATCH
> 14:13:01.438 [main] DEBUG org.apache.http.headers - http-outgoing-0 <<
> CF-Cache-Status: DYNAMIC 14:13:01.438 [main] DEBUG
> org.apache.http.headers - http-outgoing-0 << cf-request-id:
> 0334b1f9dc000073f98a82e200000001 14:13:01.438 [main] DEBUG
> org.apache.http.headers - http-outgoing-0 << Expect-CT:
> max-age=604800,
> report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
> 14:13:01.438 [main] DEBUG org.apache.http.headers - http-outgoing-0 <<
> Server: cloudflare 14:13:01.438 [main] DEBUG org.apache.http.headers -
> http-outgoing-0 << CF-RAY: 5a0152a2fd3d73f9-IAD 14:13:01.445 [main]
> DEBUG org.apache.http.impl.execchain.MainClientExec - Connection can
> be kept alive indefinitely 14:13:01.467 [main] DEBUG
> org.apache.http.client.protocol.ResponseProcessCookies - Cookie
> accepted [__cfduid="dae179e331605780", version:0, domain:mycomp.com,
> path:/, expiry:Wed Jul 08 14:13:00 IST 2020] 14:13:01.469 [main] DEBUG
> org.springframework.web.client.RestTemplate - Response 400 BAD_REQUEST
> 14:13:01.471 [main] DEBUG
> org.apache.http.impl.conn.PoolingHttpClientConnectionManager -
> Connection [id: 0][route: {s}->https://api.mycomp.com:443] can be kept
> alive indefinitely 14:13:01.471 [main] DEBUG
> org.apache.http.impl.conn.DefaultManagedHttpClientConnection -
> http-outgoing-0: set socket timeout to 0 14:13:01.471 [main] DEBUG
> org.apache.http.impl.conn.PoolingHttpClientConnectionManager -
> Connection released: [id: 0][route:
> {s}->https://api.mycomp.com:443][total kept alive: 1; route allocated:
> 1 of 5; total allocated: 1 of 10] Exception in thread "main"
> org.springframework.web.client.HttpClientErrorException$BadRequest:
> 400 :
> [{"id":"8bcc1231-444f-4795-a142-fe0d5c788bb4","timeStamp":"2020.06.08.08.43.01.289","requestURL":"http://api.mycomp.com/pb/35969258/contents/16828","requestMethod":"POST","error":"Bad
> Request"}]    at
> org.springframework.web.client.HttpClientErrorException.create(HttpClientErrorException.java:101)
>   at
> org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:170)
>   at
> org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:112)
>   at
> org.springframework.web.client.ResponseErrorHandler.handleError(ResponseErrorHandler.java:63)
>   at
> org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:785)
>   at
> org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:743)
>   at
> org.springframework.web.client.RestTemplate.execute(RestTemplate.java:717)
>   at
> org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:605)
>   at
> com.tandf.util.invalidproductentitlementworker.LoginTest.main(LoginTest.java:71)
java spring spring-boot rest-client
2个回答
1
投票

看起来您使用的是错误的MIME类型。 Microsoft Excel文件的MIME类型为application/vnd.openxmlformats-officedocument.spreadsheetml.sheet(请参见common MIME types);也可以使用通用的application/octet-stream,从服务器端将其解释为“未知文件类型”。


0
投票

同时上传文件时,我们还需要丢失CONTENT_DISPOSITION

© www.soinside.com 2019 - 2024. All rights reserved.