Getting Invalid http header / Invalid Data when trying to GET

Elba 141 Reputation points
2021-02-15T03:25:31.95+00:00

I am getting an Invalid http header when I try to implement a GET in C#. This GET works when I try it in Postman. But when I run the program, I get the error message below.

This is what the code looks like:

  public static void getObjects(string sessionID)
        {
            var client = new RestClient("https://generic-server.com/api/v10.3/metadata/vobjects/");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", sessionID);
            IRestResponse response = client.Execute(request);
            Console.WriteLine("Here's the response: "  + response.Content + " " + response.Content.Length);
            Console.WriteLine("Here's the error message: " + response.ErrorMessage);
        }

This is what the output looks like:

Here's the User ID: 5228255
Here's the response: {"responseStatus":"FAILURE","errors":[{"type":"INVALID_DATA","message":"Invalid http header [Accept: application/json, text/json, text/x-json, text/javascript, application/xml, text/xml]"}]} 190
Here's the error message:

Any thoughts on why I get these error messages?

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,560 questions
0 comments No comments
{count} votes

Accepted answer
  1. Elba 141 Reputation points
    2021-02-16T05:04:10.483+00:00

    Thank you @Michael Wang for responding.

    Yes I used Postman to generate the code. As you can see, the code you generated is identical to mine.

    The Post command I am trying to execute is as follows:

    $ curl -X GET -H "Authorization: {SESSION_ID}" \  
    https://{server}/api/{version}/metadata/vobjects  
    

    However I am getting an invalid data / invalid header

    {"responseStatus":"FAILURE","errors":[{"type":"INVALID_DATA","message":"Invalid http header [Accept: application/json, text/json, text/x-json, text/javascript, application/xml, text/xml]"}]} 190  
    Here's the error message:  
    

    Can you help me understand why I am getting this error message?


1 additional answer

Sort by: Most helpful
  1. Michael Wang-MSFT 1,061 Reputation points
    2021-02-15T07:43:57.833+00:00

    Hi, @Elba

    Postman supports to generate code snippet with request setting.

    ![67966-image.png

    Click </> to generate codes.

    68073-image.png


    If the answer doesn’t solve your issue, please provide more details of error that will help us track down what’s happening.
    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best Regards,
    Michael Wang

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.