卷曲--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中,但是错误总是一样的... –