Coder Social home page Coder Social logo

Comments (5)

ruicaramalho avatar ruicaramalho commented on July 26, 2024

The problem was TLS. by default Visual Studio is not using TLS12 as the first option.

Please change the constructor in Client.cs to:

        public Client(string endpoint = null, string applicationKey = null,
            string applicationSecret = null, string consumerKey = null,
            TimeSpan? defaultTimeout = null, char parameterSeparator = ',',
            HttpClient httpClient = null, string confFileName = ".ovh.conf") : this()
        {
            LoadConfiguration(endpoint, applicationKey, applicationSecret, consumerKey, parameterSeparator, confFileName);
            _defaultTimeout = defaultTimeout ?? _defaultTimeout;

            //specify to use TLS 1.2 as default connection
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

            _httpClient = httpClient ?? _httpClient ?? new HttpClient(handler);
        }

from csharp-ovh.

ruicaramalho avatar ruicaramalho commented on July 26, 2024

Quick fix solution for the current version

Necessary references:

using System;
using Ovh.Api;
using System.Threading.Tasks;
using System.Net;
using System.Net.Http;
        /// <summary>
        /// Customise our client.
        /// </summary>
        /// <returns></returns>
        internal static Client NoProxyClient()
        {
            //specify to use TLS 1.2 as default connection, otherwise it will not work...
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

            //Remove Proxy, In my case we have a proxy in the LAN
            HttpClientHandler handler = new HttpClientHandler
            {
                UseProxy = false
            };

            var httpClient = new HttpClient(handler);
            return new Client(null,null,null,null,null,',',httpClient);
        }

        public static async Task<string> MyInfo()
        {

            Client client = NoProxyClient();

            string me = await client.GetAsync("/me");
            return me;

        }

from csharp-ovh.

Namaneo avatar Namaneo commented on July 26, 2024

Hello,

Thanks for opening an issue, and for your investigation!

I could not reproduce on my side, using a .NET Core 3.1 console application running on Windows 10 20H2. Looking at the documentation, starting with .NET Framework 4.7, it seems this configuration depends on the system:

  • Are you using an older framework?
  • Are you using a Windows version that don't have it enabled?

In any case, ServicePointManager.SecurityProtocol alters the whole process, therefore we should not manipulate it from inside the library as per Microsoft recommendations. However, you can apply that change in your own code if this is an acceptable solution for you.

from csharp-ovh.

ruicaramalho avatar ruicaramalho commented on July 26, 2024

I had the problem while debuging using Visual Studio 2017 in a windows 10 on a WebProject with for NetFramework 4.6.2.
The fault is probably because of the IIS Express used by VS in debug.

Just want to add that the code is clean and well comented, well done.

from csharp-ovh.

ruicaramalho avatar ruicaramalho commented on July 26, 2024

The problem is VS in debug mode using the IIS Express.

from csharp-ovh.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.