© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
2 replies
senkd

Graph API - HttpClient returns 404, but curl (and Graph Explorer) for same request works?

I'm completely lost. I've resorted to just calling curl from C# as this is completely non-sensical to me. I started with using the Graph SDK, which I had multiple issues with, and I also received a "Not Found" error when trying to use graphClient.Groups[groupId].Threads[ThreadId].PostAsync(body) My current code looks like this:

var token =  await GetUserTokenAsync(); //gets the latest token from the GraphClient

using (var client = new HttpClient())
{
    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
    using (var content = new StringContent(body))
    {
        content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

        var postUrl = new UriBuilder($"https://graph.microsoft.com/v1.0/groups/{groupId}/threads/{threadId}/reply").ToString();

        var resp = await client.PostAsync(postUrl, content);

        if (!resp.IsSuccessStatusCode)
        {
            //same Url and body
            Console.WriteLine($"Error: Unable to post reply to group {groupId} thread {threadId}. The server said {await resp.Content.ReadAsStringAsync()}");
            String curlCommand = $"curl -i -X POST -H \"Authorization: Bearer {token}\" -H \"Content-Type: application/json\" -d '{body}' \"https://graph.microsoft.com/v1.0/groups/{groupId}/threads/{threadId}/reply\"";
            Console.WriteLine($"Try this with curl: {curlCommand}");
        }
    }
}
var token =  await GetUserTokenAsync(); //gets the latest token from the GraphClient

using (var client = new HttpClient())
{
    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
    using (var content = new StringContent(body))
    {
        content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

        var postUrl = new UriBuilder($"https://graph.microsoft.com/v1.0/groups/{groupId}/threads/{threadId}/reply").ToString();

        var resp = await client.PostAsync(postUrl, content);

        if (!resp.IsSuccessStatusCode)
        {
            //same Url and body
            Console.WriteLine($"Error: Unable to post reply to group {groupId} thread {threadId}. The server said {await resp.Content.ReadAsStringAsync()}");
            String curlCommand = $"curl -i -X POST -H \"Authorization: Bearer {token}\" -H \"Content-Type: application/json\" -d '{body}' \"https://graph.microsoft.com/v1.0/groups/{groupId}/threads/{threadId}/reply\"";
            Console.WriteLine($"Try this with curl: {curlCommand}");
        }
    }
}


and when I run the generated curl command... it works? Exact same url, exact same token, exact same content type... but curl (and Graph Explorer) works, and HttpClient doesn't? What in the world am I missing?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ HttpClient SendAsync works with .Wait() but not with await
C#CC# / help
3y ago
✅ Microsoft Graph API
C#CC# / help
4y ago
❔ HttpClient Request headers automatically capitalizing.
C#CC# / help
3y ago
Graph API Outlook feature
C#CC# / help
2y ago