tencent cloud

Feedback

Last updated: 2024-07-12 17:42:57
    Note:
    When using web-related APIs in Mini Programs/Mini Games, developers should note the following issues in advance.

    Configuration of Server Domain Name

    Each mini program needs to set a communication domain name in advance, and the mini program can only communicate with the specified domain name. This includes normal HTTPS requests (wx.requestt), uploading files (wx.uploadFile), downloading files (wx.downloadFile) and Websocket communication (wx.connectSocket), UDP communication (wx.createUDPSocket), TCP communication (wx.createTCPSocket).
    The network interface only allows communication with non-local IPs and configured server domains on the same LAN.

    Configuration process

    Configure the server domain name in Mini Program Console > Settings > Development Settings > Server Domain Name. Configuration notes:
    The domain name supports the https (wx.request, wx.uploadFile,wx.downloadFile) protocol, the wss (wx.connectSocket) protocol, and the tcp and udp protocols;
    The domain name cannot use an IP address or localhost.
    Ports can be configured, such as https://miniApp.com:8080, but when configured, requests can only be made to https://miniApp.com:8080. Requests to URLs such as https://miniApp.com, https://miniApp.com:9091, etc. will fail.
    If no port is configured. For example, https://miniApp.com, then the request URL cannot contain a port, not even the default port 443. Requests to https://miniApp.com:443 will fail.

    Network Request

    Timeout

    The default timeout and maximum timeout are both 60s;
    The timeout can be configured in app.json;
    It is also possible to specify a timeout when the interface is called, e.g. wx.request({ timeout: 5000 }) in ms. The timeout configuration for the interface call takes precedence over the configuration in app.json.

    Use Limits

    The referer header of a network request is optional. Its format is always https://servicewechat.com/{appid}/{version}/page-frame.html, in which {appid} is the Mini Program's appid and {version} is the version number of the Mini Program. A version number of 0 means it is a developer version, trial version, or review version. A version number of devtools means it is the Weixin DevTools. Those with a version number other than the above ones are formal versions;
    The maximum concurrency of wx.request, wx.uploadFile,wx.downloadFile is 10;
    The maximum concurrency limit for wx.connectSocket is 5;
    When the Mini Program is running in the background, if a network request does not end within 5s, an error message of fail interrupted will be called back. The network request API cannot be called until the Mini Program client is re-opened.

    Return value encoding

    The values returned by the server should be UTF-8 encoded. The Mini Program will try to convert non-UTF-8 encoded return values but may fail;
    The Mini Program automatically filters the BOM header (only one BOM header is filtered).

    Callback function

    As long the value returned by the server is received, the success callback is triggered regardless of statusCode. Determine the return value based on the business logic.

    FAQs

    HTTPS certificate

    Mini Programs must use HTTPS/WSS to initiate a network request. During the request, the system verifies the HTTPS certificate used by the server domain name. If the verification fails, the request is not successfully initiated. Due to system limitations, different platforms have different levels of stringency for certificates. To ensure the compatibility of Mini Programs, we recommend that developers configure the certificate according to the highest standard and use the relevant tools to check whether the existing certificate meets the requirements.
    The requirements for certificates are as follows:
    The HTTPS certificate must be valid;
    Use a trusted certificate, i.e., the root certificate has been built into the system;
    The domain name of the website where the SSL certificate is deployed must be the same as the domain name for which the certificate was issued;
    The certificate must not have expired;
    The certificate's trust chain must be complete (server configuration is required);
    Self-signed certificates is not supported for iOS;
    Certificates in iOS must meet Apple's App Transport Security (ATS) requirements;
    TLS 1.2 or above is required. However, TLS 1.2 is not supported on some older Android models, so make sure HTTPS server supports TLS 1.2 or below;
    Some CAs may not be trusted by the operating system. Take note of the announcements of the Mini Program and other systems when selecting certificates.
    Note:
    The validity of the certificate can be verified using the openssl s_client -connect example.com:443 command, or you can use other online tools;
    In addition to the web request API, if there is any abnormality in other HTTPS requests in the mini program, please check it according to the above process. For example, https images can't be loaded, audio and video can't be played, and so on.

    Skip domain name verification

    In the Weixin DevTools, the Do not verify the request domain name, TLS version, and HTTPS certificate in development environment option can be enabled to skip verification of the server domain name. In this case, the server domain name will not be verified in the Weixin DevTools or when debugging mode is enabled on your phone.
    After the server domain name is configured, we recommend you disable this option during development and test the domain name on each platform to ensure it is correct.
    Note:
    If you see the phenomenon of "can send request with debugging mode on, can't send request with debugging mode off" on your mobile phone, please make sure that the domain name verification has been skipped, and make sure that the server domain name and certificate configuration are correct.
    If you encounter "internal server error", please try the following methods to check yourself ① Change the browser ② Refresh the web page ③ Check whether the file is placed in the correct server root directory. Checking method: Splicing the URL according to the following rules, and try to access whether it is successful or not: https://m.da9c.cn/Filename.
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support