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 + "}");
7
  • have you seen that in Java your security header token will be VST { token }? In C# at least I can't see the "{" chars maybe is that? Commented Oct 7, 2015 at 12:35
  • // Authorization header value format is "VST {tokenvalue}" Commented Oct 7, 2015 at 12:37
  • Try to debug your full request, because the only header is that. It must be a little error there Commented Oct 7, 2015 at 12:38
  • Error: Bad Request - Invalid Header.. new AuthenticationHeaderValue("VST", securityToken);--> .NET C# Code. Need to write similar line of code in java. Commented Oct 7, 2015 at 13:02
  • try httpGet.setHeader("VST",{token}); Commented Oct 7, 2015 at 13:10

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

3 Comments

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.
stackoverflow.com/questions/19039450/…. it is working now.. Thanks acostela httpGet.setHeader("Authorization","VST "+token);
oh you're welcome. I will edit the answer so it fits with your final solution

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.