捲曲--location我有這樣的捲曲在Java中複製與Java
捲曲-i -L 的https:// {用戶名} {}密碼@ url.com/exportsData
響應
HTTP/1.1 302 Found
Date: Wed, 17 May 2017 11:29:29 GMT
Content-Length: 0
Connection: keep-alive
Location: https://test-cache-ss.s3.amazonaws.com/queries/...
HTTP/1.1 200 OK
x-amz-id-2: sjahjsahfjhsa/safksjafksak+skajfksajfhsajhj=
x-amz-request-id: 33346FA02921212131
Date: Wed, 17 May 2017 11:29:31 GMT
Last-Modified: Wed, 17 May 2017 11:07:57 GMT
x-amz-expiration: expiry-date="Thu, 01 Jun 2017 00:00:00 GMT", rule-id="Delete after 14 days"
ETag: "7d519e24ae5c1ce3881c59d0670cb8e4-1"
Accept-Ranges: bytes
Content-Type: application/octet-stream
Content-Length: 1137090
Server: AmazonS3
{"USER_ID":"265117459845"}
這是我的代碼返回我401響應:
List<Long> ids = new ArrayList<Long>();
try (final CloseableHttpClient httpClient = HttpClientBuilder.create().build()) {
final HttpGet httpGet = new HttpGet("https://" + username + ":"
+ password + "@url.com/exportsData");
try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
final ObjectMapper mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.disable(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE);
ids = Arrays.asList(mapper.readValue(response.getEntity().getContent(), Long[].class));
}
} catch (final JsonParseException e) {
logger.error("JsonParseException", e);
} catch (final JsonMappingException e) {
logger.error("JsonMappingException", e);
} catch (final UnsupportedOperationException e) {
logger.error("UnsupportedOperationException", e);
} catch (final IOException e) {
logger.error("IOException", e);
}
} catch (final IOException e1) {
logger.error("IOException1", e1);
}
return ids;
以這種方式(總401)
List<Long> ids = new ArrayList<Long>();
final CredentialsProvider provider = new BasicCredentialsProvider();
provider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("username", "password");
try (final CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultCredentialsProvider(provider).build()) {
final HttpGet httpGet = new HttpGet("https://url.com/exportsData");
try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
final ObjectMapper mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.disable(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE);
ids = Arrays.asList(mapper.readValue(response.getEntity().getContent(), Long[].class));
}
} catch (final JsonParseException e) {
logger.error("JsonParseException", e);
} catch (final JsonMappingException e) {
logger.error("JsonMappingException", e);
} catch (final UnsupportedOperationException e) {
logger.error("UnsupportedOperationException", e);
} catch (final IOException e) {
logger.error("IOException", e);
}
} catch (final IOException e1) {
logger.error("IOException1", e1);
}
return ids;
還測試增加HttpClientBuilder
.setRedirectStrategy(new LaxRedirectStrategy()).build()
我已經錯過了還測試?
@DanielStenberg對!我更新了標題 –
@SME_Dev中間沒有代理服務器。我也測試過將setsetedirectstrategy(新的LaxRedirectStrategy())設置到HttpClientBuilder中,但是錯誤總是一樣的... –