Updated on 2026-09-08 GMT+08:00

Accessing a Real-Time Service Using HTTP or HTTPS

Context

HTTP is based on the request-response mode. That is, the client initiates a request, and the server returns a response. The server cannot proactively push data. HTTPS enhances security based on HTTP and is widely used in scenarios that require high data privacy and integrity.

HTTP sends content in plaintext and does not provide data encryption in any mode. If an attacker intercepts the packets transmitted between the web browser and website server, the attacker can directly read the information in the packets. Therefore, HTTP is not suitable for transmitting sensitive information. HTTPS communicates through HTTP, but uses SSL/TLS to encrypt data packets. HTTPS is used to authenticate website servers, protect privacy, and ensure integrity of exchanged data.

HTTP/HTTPS features:

  • Statelessness: By default, session states are not retained. Each request is processed independently. Stateful session management (such as user login status) can be implemented through cookies, sessions, or tokens.
  • Flexibility and scalability: transmission of multiple data formats, such as text (JSON/XML) and binary (images and files). You can also use the header field for scalability, such as cache control, content negotiation, and cross-origin resource sharing (CORS).
  • Wide compatibility: Native support for all typical browsers, programming languages, and frameworks, without the need to upgrade specific libraries or protocols. HTTP and HTTPS are applicable to common scenarios such as web pages, RESTful APIs, and file transfer.

Prerequisites

  • The service protocol in the network configuration is set to HTTP or HTTPS during service information configuration.
  • The image selected for the real-time service must support HTTP/HTTPS.

Constraints

When you call an API to access a real-time service, the size of the prediction request body and the prediction time are subject to the following limitations:
  • The request body must be within the allowed size set by the service's configuration; otherwise, the request will be blocked.
  • Each request must be completed within its configured timeout period, which is recalculated during data transmission.

Obtaining the Authentication Information, Local Path to the Prediction File, and URL of the Real-Time Service

  • Authentication Information

    The HTTP/HTTPS protocol itself does not introduce new authentication mechanisms; it relies on the same methods as HTTP requests.

    Obtain authentication information based on the authentication mode selected during service deployment. Authentication information is not required if no authentication is used.

    This section uses token authentication as an example. For details about how to obtain a user token, see Token-based Authentication. The real-time service APIs generated by ModelArts do not support tokens whose scope is domain. Therefore, you need to obtain the token whose scope is project.

  • Local Path to the Prediction File

    The local path to the prediction file can be an absolute path (for example, D:/test.png for Windows and /opt/data/test.png for Linux) or a relative path (for example, ./test.png).

  • URL of the Real-Time Service

    The API URL and input parameters of the real-time service: To obtain them, choose Model Inference > Real-Time Inference on the console, click the target real-time service, and obtain the information from Call Info in the Service tab.

    API URL is the URL of the real-time service. If a path is defined for apis in the model configuration file, the URL must be followed by the user-defined path, for example, {URL of the real-time service}/v1/chat/completions.

Calling a Real-Time Service via HTTP/HTTPS

The following section uses GUI software Postman for prediction and token authentication as an example to describe how to call HTTP.

  1. Download Postman and install it, or install the Postman Chrome extension. Alternatively, use other software that can send POST requests. Postman 8.11.1 is recommended.
  2. Open Postman, select a POST task, and copy the API URL obtained in Obtaining the Authentication Information, Local Path to the Prediction File, and URL of the Real-Time Service to the POST text box.
    Add authentication information into the header. The header varies depending on the authentication mode, which is the same as that in the HTTPS-compliant inference service. Take token authentication as an example: On the Headers tab page, set Key to X-Auth-Token and Value to the user token.
    Figure 1 Using Postman for prediction
  3. Click send to send the request. The result will be displayed in Response.

Request Headers Field Description

HTTP headers refer to the header components within HTTP request and response messages. HTTP header fields can be customized as needed. By default, the inference gateway forwards request headers; however, the following request headers carry system semantics specifically for model inference prediction forwarding scenarios. Avoid using these request headers, as shown in Table 1. Because validation is involved during request calls, if gateway authentication is enabled, the corresponding header fields will be overwritten.

Table 1 Headers to avoid

Header Field

Description

X-Forwarded-For

When a request is forwarded through ELB, ELB overwrites the X-Forwarded-For field to write the client's actual IP address into this header. This ensures that the system can accurately retrieve the client's origin IP address even across multi-layer proxy chains, maintaining the proper functionality of features dependent on actual IP addresses, such as IP hash session affinity and IP allow/deny lists.

X-Real-IP

When a request is forwarded through ELB, ELB overwrites the X-Real-IP field to write the client's actual source IP address into this header. This allows the system to accurately obtain the client's true IP address across multi-layer proxy chains, serving as a fallback mechanism to identify the client source and log it for troubleshooting when standard proxy headers like X-Forwarded-For are unavailable or set to unknown.

X-Forwarded-Host

When a request is forwarded through ELB, ELB overwrites the X-Forwarded-Host field to write the original access domain name into this header. This allows the system to accurately retrieve the requested host address across multi-layer proxy chains, thereby identifying the request source type (private network/public network/console), executing corresponding access control policies, and logging the event in trace logs for troubleshooting.