antnewbee
antnewbee

Reputation: 1949

Send GET request with 443 userid password prompt authentication using Java HttpClient

I want to get the response from a url by sending url parameters(GET parameters) eg. https://ebctest.cybersource.com/ebctest/DownloadReport/2014/07/23/$MerchantId/ConversionDetailReport.xml

When I hit the server I am prompted by a userid, password dialog box.

I can get the response by manually entering the id,password. How can I achieve this programatically using java.

Below is the code which I have tried till now.

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()));

When I do method.getResponseBody I get empty. I should be getting a proper response as I am getting when sending the request manually.

Upvotes: 1

Views: 899

Answers (1)

DavidC
DavidC

Reputation: 218

it Looks like basic auth, you should be able to send username and password by calling this url:

https://username:password@ebctest.cybersource.com/ebctest/D

Upvotes: 1

Related Questions