HTTPS requests in C #. Net

Source: Internet
Author: User

When interfacing with the Huawei NB-IoT platform, the HTTPS connection was used, and Huawei provided a CRT-format certificate file, but the official only gave the Java paradigm, and C # had a problem referencing the certificate, the following is the pit:

Nb_iot platform interface debugging, HTTPS authentication mode

  • First, add in the code
  • 1 New Remotecertificatevalidationcallback (CheckValidationResult);

    callback function returns true without validating the certificate

  • When only one certificate was used to study the HTTPS authentication method, it was discovered that both "checksum" and "Device-side certificate" were required, and then two certificates were imported
    1 New X509Certificate (@ "C:\ca.crt"); 2 WebRequest. Clientcertificates.add (CER2);

    Later found that there is a problem with the server address of the connection changed the connection address, return "Cryptographicexception" exception, find a workaround, add code

    1 servicepointmanager.securityprotocol = SECURITYPROTOCOLTYPE.TLS;

    To use TLS encryption mode. (note here that you need to upgrade to more than. NET framework4.5 for TLS encryption)

    • Tried to try another format of the certificate, but are not available, using the JKS format of the certificate, generated direct error "Cannot find the requested object", suspect that the certificate format C # does not support, it seems that JKs is a Java tool specifically used in the format. After you have used another format, you can generate a certificate, but the return display " Failed to create SSL/TLS secure channel "
    • Change X509Certificate to X509Certificate2 return 400 error stating certificate validation passed but request format problematic cause to be analyzed
    • The next morning (April 12) found that the "Content-type" in the HTTPS header more than a space "Content -type", resulting in a malformed, pure hand mistakenly do not know how to enter the space, remove the space after the request succeeded.

HTTPS requests in C #. Net

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.