2

Below is the example in .NET C# language to get resource list for the user

Prepare HttpRequest with proper HEADER details

    HttpClient client = new HttpClient();
    // Authorization header value format is "VST {tokenvalue}"
    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("VST", securityToken); 
    client.DefaultRequestHeaders.Add("ContentType", "text/json");
    client.DefaultRequestHeaders.Add("Accept", "text/json");*

Need to write the similar code in Java, I have written the below code in java to access the web-service.

Getting error:

HTTP Error 400. 

The request has an invalid header name.

HttpGet request = new HttpGet(getRequestUrl(baseUrl,   VideologyConstants.GET_CUSTOMERS_API_URL));
request.setHeader(HttpHeaders.AUTHORIZATION, "VST {" + securityToken + "}");
VIKASH SINHA
  • 250
  • 3
  • 17

1 Answers1

2

client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("VST", securityToken);

Will produce this header value

Authorization: VST {securityToken}

The way that you can add that header in java is.

httpGet.setHeader("Authorization","VST "+token)

Here you can check the java API http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/index.html

VIKASH SINHA
  • 250
  • 3
  • 17
acostela
  • 2,597
  • 3
  • 33
  • 50
  • Tried and setting the correct header in the HttpGet Method but getting the same error. .Net C# code is using AuthenticationHeaderValue class to set security token.. may be it works in different way. – VIKASH SINHA Oct 07 '15 at 13:35
  • http://stackoverflow.com/questions/19039450/adding-authorization-to-the-headers. it is working now.. Thanks acostela httpGet.setHeader("Authorization","VST "+token); – VIKASH SINHA Oct 08 '15 at 07:20
  • oh you're welcome. I will edit the answer so it fits with your final solution – acostela Oct 08 '15 at 07:27