Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

C# (Httpclient) Code generated from Postman not working #749

Unanswered
BobHillDev asked this question in Q&A
Discussion options

I have a working example in Postman and when I generate the C# (HttpClient) code it fails with error 404. I was able to successfully generate the Python code for this and get it running in Python. Has anyone run into similar issues, and if so, how did you resolve it?

Here is the code. Due to sensitivity of API access, the actual URL's and credentials have been placed into constants outside of this function.

` private async Task testAPIAsync()
{
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, HIP_URL);
request.Headers.Add("Accept", "application/JSON");
request.Headers.Add("Auth-Request-Type", "Named-User");
request.Headers.Add("Authorization", HIP_BEARER);
request.Headers.Add("Cookie", "BrowserId=mk-rq3GsEe68Oa_Azf5OOQ; CookieConsentPolicy=0:1; LSKey-c$CookieConsentPolicy=0:1; oinfo=c3RhdHVzPURFTU8mdHlwZT02Jm9pZD0wMEQzUzAwMDAwMDh0emI=");

        var collection = new List<KeyValuePair<string, string>>();        
        collection.Add(new KeyValuePair<string, string>("scope", "api openid"));
        collection.Add(new KeyValuePair<string, string>("response_type", "code_credentials"));
        collection.Add(new KeyValuePair<string, string>("client_id", HIP_CLIENT_ID));
        collection.Add(new KeyValuePair<string, string>("redirect_uri", HIP_REDIRECT_URI));
        collection.Add(new KeyValuePair<string, string>("username", HIP_USERNAME));
        collection.Add(new KeyValuePair<string, string>("password", HIP_PASSWORD));
        var content = new FormUrlEncodedContent(collection);
        request.Content = content;
        try
        {
            var response = await client.SendAsync(request);
            response.EnsureSuccessStatusCode();
            Console.WriteLine(await response.Content.ReadAsStringAsync());
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
        }            
    }

`
The response that I get is a 404 error, and it seems like it is checking generating the 404 on HIP_REDIRECT_URI and not the HIP_URL in the request created with the POST verb.

Any help on this would be greatly appreciated. I can also share the result of the response if that will help.

Thanks!
Bob

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
1 participant
Morty Proxy This is a proxified and sanitized view of the page, visit original site.