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

  • SEARCH
  • Home
  • 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 6670835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:18:57+00:00 2026-05-26T03:18:57+00:00

I want to access a Restful web service. I want the request should be

  • 0

I want to access a Restful web service. I want the request should be in the following format.

GET /API/Contacts/username HTTP/1.1 
HOST: $baseuri:port 
Accept: text/xml 
Authorization: Basic ZmF0aWdhYmxlIGdlbmVyYXR=

And also I am calling the web service though HTTPS protocol.
The folowing is the code I am using :

HttpGet get = new HttpGet("https://secure.myapp.com/MyApp/API/Contacts/myname");

  get.addHeader("Accept","text/xml");
  get.addHeader("Authorization","Basic ZmF0aWdhYmxlIGdlbmVyYXR=");          
  get.addHeader("Host","https://secure.myapp.com");
  get.addHeader("Connection Use","HTTP 1.1");

  DefaultHttpClient client =  new DefaultHttpClient();
  ResponseHandler objHandler = new BasicResponseHandler();
  String getResponse = client.execute(get,objHandler); 

But I am getting an Error : 400 Bad request.

I am not sure whether my code is correct. Is it necessary to specify the method (GET, POST or PUT) explicitly in the header?

Please help me…
Thnking You….

  • 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-26T03:18:58+00:00Added an answer on May 26, 2026 at 3:18 am

    Ohh…
    That was my mistake.
    I did not keep the order of adding headers.
    When I changed its order according to the Request it is working fine.

    In the request the HOST should be the first parameter.
    The following is the corrected code.

    get.addHeader("Host","secure.myapp.com");
    get.addHeader("Accept","text/xml");   
    get.addHeader("Authorization","Basic ZmF0aWdhYmxlIGdlbmVyYXR=");                
    get.addHeader("Connection Use","HTTP 1.1"); 
    

    Sorry to disturb you all…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to access an external RESTFul Web service via Java, and use an
i have created a Java Restful Web service . Now i want to access
I have a RESTful web service and I want to access it from Android.
I'm developing a web-service using WCF, which I want to access using a client
There is one controversy I see in using Web APIs (RESTful service) to access
I want to host an MVC 4 Web API project on Azure. I need
I want to implement spring security on a jersey Restful web service, both on
I have a restful api I want to access, and my app has its
I want to implement a basic RESTful service using Tomcat. The API requires authorisation
TL;DR Summary: Can I configure MVC Web API routing for HTTP GET, PUT &

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.