gpt4 book ai didi

java - 使用 Java HttpClient 发送带有 443 用户 ID 密码提示身份验证的 GET 请求

转载 作者:太空宇宙 更新时间:2023-11-04 06:38:49 24 4
gpt4 key购买 nike

我想通过发送url参数(GET参数)来获取url的响应例如。 https://ebctest.cybersource.com/ebctest/DownloadReport/2014/07/23/ $MerchantId/ConversionDetailReport.xml

当我访问服务器时,系统会出现用户 ID、密码对话框提示。

我可以通过手动输入id、密码来获取响应。我怎样才能使用java以编程方式实现这一点。

下面是我迄今为止尝试过的代码。

final HttpClient httpClient = new HttpClient();
httpClient.getState().setCredentials(new AuthScope(null, 443), new UsernamePasswordCredentials(userName, password));
httpClient.getParams().setParameter("http.socket.timeout", Integer.valueOf(10000));
httpClient.getState().setAuthenticationPreemptive(true);

final GetMethod method = new GetMethod("https://ebctest.cybersource.com/ebctest/DownloadReport/2014/07/23/$merchantId/ConversionDetailReport.xml");

final InputSource is = new InputSource(new ByteArrayInputStream(method.getResponseBody()));

当我执行 method.getResponseBody 时,我变得空了。我应该得到正确的响应,就像手动发送请求时得到的那样。

最佳答案

它看起来像基本身份验证,您应该能够通过调用此网址发送用户名和密码:

https://用户名:密码@ebctest.cybersource.com/ebctest/D

关于java - 使用 Java HttpClient 发送带有 443 用户 ID 密码提示身份验证的 GET 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24953797/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com