1

Using GraphClient from Microsoft.SDK.Graph I can see the queries are going out in fiddler, none of them use HTTP/2.0 but I get this error:

ArgumentException: Only HTTP/1.0 and HTTP/1.1 version requests are currently supported. Parameter name: value

private async Task<UserAccount> FetchAzurePropsFromGraph()
        {
            var scopes = new[] { "User.Read" };
            var clientId = EWSMailboxSyncProvider.CLIENT_ID;
            var tenantId = ServicesConfiguration.GetStoredTenantID();
            System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();
            var transport = new Azure.Core.Pipeline.HttpClientTransport(client);
            var options = new TokenCredentialOptions
            {
                AuthorityHost = AzureAuthorityHosts.AzurePublicCloud,
                Transport = transport
            };

            var userNamePasswordCredential = new UsernamePasswordCredential(
                    _o365UserName, _o365Password, tenantId, clientId, options);
            var graphClient = new Microsoft.Graph.GraphServiceClient(userNamePasswordCredential, scopes);
            var user = await graphClient.Users[_emailAddress].Request().GetAsync();
            var result = new UserAccount();
            if (user != null)
            {
                result.DisplayName = user.DisplayName;
                result.City = user.City;
                result.Company = user.CompanyName;
                result.DisabledAccount = !(user.AccountEnabled ?? true);
                result.DistinguishedName = user.OnPremisesDistinguishedName;
                result.DomainName = user.OnPremisesDomainName;
                result.EmailAddresses.Add(user.Mail);
                foreach (var mail in user.OtherMails)
                {
                    result.EmailAddresses.Add(mail);
                }
            }
            return result;
        }
  • 1
    [Only HTTP/1.0 and HTTP/1.1 version requests are currently supported - 1](https://stackoverflow.com/questions/68161625/only-http-1-0-and-http-1-1-version-requests-are-currently-supported), [Only HTTP/1.0 and HTTP/1.1 version requests are currently supported - 2](https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/1367) and [Only HTTP/1.0 and HTTP/1.1 version requests are currently supported - 3](https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/1275) – Ecstasy Jun 15 '22 at 07:03

1 Answers1

1

I'm the same issue with you, and i solved it by create custom request to Microsoft server

public static string GetAzureAccessToken(){
     var client = new RestClient("https://login.microsoftonline.com:443/your_tenantid/oauth2/v2.0/token");
     var request = new RestRequest(Method.POST);
     request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
     request.AddParameter("grant_type", "password");
     request.AddParameter("username", "your_email");
     request.AddParameter("password", "password");
     request.AddParameter("scope", "https://graph.microsoft.com/.default");
     request.AddParameter("tenant", "your_tenantid");
     request.AddParameter("client_id", "your_client_id");
     IRestResponse response = client.Execute(request);

     if(response.IsSuccessful)
     {
         var result = JsonConvert.DeserializeObject<dynamic>(response.Content);

         return result.access_token;
     }
     else
     {
         return "Fail";
     }

After get the access token i create a request to server with the accesstoken i have:

public static string GetMailBox(string accessToken){
        var client = new RestClient("https://graph.microsoft.com/v1.0/users/"your_email"/messages?$top=10");
        client.Timeout = -1;
        var request = new RestRequest(Method.GET);
        request.AddHeader("Authorization", "Bearer " + accessToken);
        IRestResponse response = client.Execute(request);

        if (response.IsSuccessful)
        {

            var result = JsonConvert.DeserializeObject<dynamic>(response.Content);

            return result.value.ToString();
        }
        else
        {
            return "Fail";
        }

You can read this document for create more request like example GetMailBox i put above Microsoft Graph API document