Updated on 2024-09-13 GMT+08:00

Setting Proxy Information

SetProxyInfo

API Description

This API is used to set proxy information.

Precautions

  1. This API is optional. By default, no proxy is used.
  2. This API is an asynchronous API. The return value only indicates whether the API is successfully called. The actual service processing result is returned in the corresponding callback function.

Method Definition

HWM_SDK_AGENT_API hwmsdk::HwmErrCode SetProxyInfo(const HwmProxyInfo* proxyInfo);

Callback Function

virtual void OnSetProxyInfoResult(hwmsdk::HwmErrCode ret, const char* reason) {};

Parameter Description

Table 1 HwmProxyInfo description

Parameter

Mandatory

Type

Description

proxyConfigPolicy

Yes

HwmProxyConfigPolicy

Proxy configuration policy.

server

No

char[]

Proxy server address.

serverPort

No

unsigned short

Proxy server port.

account

No

char[]

Proxy server account.

password

No

char[]

Proxy server password.

Table 2 Enumerated values of HwmProxyConfigPolicy

Enumerated Value

Description

HWM_PROXY_CONFIG_POLICY_CUSTOM

Use a proxy with custom configurations.

HWM_PROXY_CONFIG_POLICY_OFF

Do not use a proxy.

HWM_PROXY_CONFIG_POLICY_AUTO

Use the system proxy.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
*  Set proxy information.
*/
void demoSetProxyInfoDlg::SetProxyInfo()
{
    CString serverCString;
    CString portCString;
    CString accountCString;
    CString pwdCString;
    m_proxyServerEdit.GetWindowText(serverCString);
    m_proxyPortEdit.GetWindowText(portCString);
    m_proxyUserNameEdit.GetWindowText(accountCString);
    m_proxyPswEdit.GetWindowText(pwdCString);

    hwmsdkagent::HwmProxyInfo proxyInfo{};
    proxyInfo.proxyConfigPolicy = hwmsdkagent::HWM_PROXY_CONFIG_POLICY_CUSTOM;
    string server = CTools::UNICODE2UTF(serverCString.GetString());
    strncpy_s(proxyInfo.server, server.c_str(), HWM_MAX_URL_LEN);
    // Set the username and password only for a custom proxy.
    int port = _ttoi(portCString);
    if (port > 65535 || port < 0)
    {
        MessageBox(L"The port number ranges from 0 to 65535.");
        return;
    }
    proxyInfo.port = port;
    string account = CTools::UNICODE2UTF(accountCString.GetString());
    strncpy_s(proxyInfo.account, account.c_str(), HWM_MAX_ACCOUNT_LEN);

    string pwd = CTools::UNICODE2UTF(pwdCString.GetString());
    strncpy_s(proxyInfo.password, pwd.c_str(), HWM_MAX_PASSWORD_LEN);
    pwd.assign(pwd.length(), '\0');
    int ret = hwmsdkagent::SetProxyInfo(&proxyInfo);
    memset(&proxyInfo, 0, sizeof(proxyInfo));
    if (hwmsdk::HWM_COMMON_SUCCESS != ret)
    {
        AfxMessageBox(_T("set proxy info error"));
        return;
    }
    CDialogEx::OnOK();
}