Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6695717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:15:20+00:00 2026-05-26T06:15:20+00:00

I have the following REST get Request that works successfully: The result is a

  • 0

I have the following REST get Request that works successfully:

enter image description here

The result is a XML document that I then want to parse. I tried the same in Java:

I use the following code:

public void getRootService() throws ClientProtocolException, IOException {

    HttpGet httpGet = new HttpGet("https://localhost:9443/ccm/rootservices");
    httpGet.setHeader("Accept", "text/xml");
    HttpResponse response = client.execute(httpGet);
    HttpEntity entity = response.getEntity();
    InputStream in = entity.getContent();
    String projectURL = XMLDocumentParser.parseDocument(in);

    System.out.println(projectURL);
    HttpGet getProjectsRequest = new HttpGet("https://localhost:9443/ccm/process/project-areas");
    getProjectsRequest.setHeader("Content-Type", "application/xml;charset=UTF-8");
    getProjectsRequest.setHeader("Accept-Charset", "UTF-8");
    getProjectsRequest.setHeader("Accept", "application/xml");


    ResponseHandler<String> handler = new BasicResponseHandler();
    String projectResponse = client.execute(getProjectsRequest, handler);
    //String projectResponse = client.execute(getProjectsRequest, handler);

    System.out.println(projectResponse);

}

But how can I do the authentication? I tried to just add another header field for the value “Authorization” but then I don’t get the same result.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:15:20+00:00Added an answer on May 26, 2026 at 6:15 am

    I think you have to create a UsernamePasswordCredentials, something along the lines of (untested);

    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(
        new AuthScope("somehost", AuthScope.ANY_PORT), 
        new UsernamePasswordCredentials("username", "password"));
    
    HttpClient httpclient = new DefaultHttpClient();
    httpclient.setCredentialsProvider(credsProvider);
    

    See http://hc.apache.org/httpcomponents-client-ga/tutorial/html/authentication.html

    Edit:
    Just tried the following code and successfully called a REST service on our dev environment that is BASIC protected.

    public static void main(String[] args) throws ClientProtocolException, IOException {
        CredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(
            new AuthScope("dev.*******.com", AuthScope.ANY_PORT), 
            new UsernamePasswordCredentials("*****", "******"));
    
    
        DefaultHttpClient client = new DefaultHttpClient();
        client.setCredentialsProvider(credsProvider);
    
        String url = "http://dev.******.com:18081/path/to/service/id.xml";
    
        HttpGet get = new HttpGet(url);
        ResponseHandler<String> handler = new BasicResponseHandler();
        String resp = client.execute(get, handler);
    
        System.out.println(resp);
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a REST API using Django Tastypie. Given the following code The models
I'm just getting into using REST and have started building my first app following
I have following plist: <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE plist PUBLIC -//Apple//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd>
I have following script that executes all the .reg files in the current directory.
I have a Spring MVC and Resteasy based REST service that i need to
I have a Self-Hosted (Console App) WCF REST service with the following binding: WebMessageEncodingBindingElement
I'm trying to get the sample code from Mozilla that consumes a REST web
I have a REST service that I'm trying to call. It requires something similar
I have the following kind of data returned to me in xml format (many
I have the following XAML code: <phone:PhoneApplicationPage.ApplicationBar> <shell:ApplicationBar IsVisible=True IsMenuEnabled=False x:Name=PageBar> <shell:ApplicationBarIconButton IconUri=/Assets/Icons/appbar.questionmark.rest.png Text=Help

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.