Skip to content

Commit 252fdf4

Browse files
committed
docs: add URL encoding guidance for API parameters (2 files)
- Added URL encoding rules, symbol table, and examples in RU article (1 file) - Added matching EN section with encoding guidance and examples (1 file) Result: clarified safe parameter encoding to prevent API errors
1 parent 18dc2fe commit 252fdf4

2 files changed

Lines changed: 97 additions & 1 deletion

File tree

docs/ZennoBrowser/zb-public-API/getting-started-with-the-zennobrowser-api.mdx

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,51 @@ import DisclaimerNotice from '@site/src/components/DisclaimerNotice';
4545

4646
1. После удаления токена он будет продолжать работать ещё в течение 1,5–2 часов;
4747
2. После истечения срока действия токена он перестанет работать;
48-
3. Если вы потеряли ранее созданный токен, вы можете создать новый.
48+
3. Если вы потеряли ранее созданный токен, вы можете создать новый.
49+
50+
51+
---
52+
53+
## «Кодирование параметров (URL Encoding)»
54+
55+
### **Важно: Передача спецсимволов в значениях**
56+
57+
Если вы формируете запрос вручную (через `HttpClient`, `fetch` или `curl`), обязательно выполняйте **URL-encoding для значений** параметров.
58+
59+
В частности это касается параметра `screen=HD+`. Если не закодировать `+`, сервер интерпретирует его как пробел, и вы получите ошибку.
60+
61+
**Пример для `screen=HD+`:**
62+
63+
* **Неверно:** `.../create?screen=HD+`
64+
* **Верно:** `.../create?screen=HD%2B`
65+
66+
### **Таблица часто используемых символов**
67+
68+
Для корректной работы API следующие символы в **значениях параметров** должны быть заменены.
69+
70+
Кодируйте эти символы, только если они являются частью передаваемых данных (значений).
71+
72+
| Символ | Описание | Код (Encoded) |
73+
| :---- | :---- | :---- |
74+
| \+ | Плюс (как в HD+) | %2B |
75+
| | Пробел | %20 |
76+
| & | Амперсанд (разделитель параметров) | %26 |
77+
| \= | Равно | %3D |
78+
| ? | Знак вопроса | %3F |
79+
| / | Слэш | %2F |
80+
| : | Двоеточие | %3A |
81+
82+
### **Примеры реализации**
83+
84+
**C\# (HttpClient):** Вместо прямой склейки строк можно используйте метод `Uri.EscapeDataString()` для значения параметра, где могут быть спецсимволы.
85+
``` csharp
86+
string screen = "HD+";
87+
string url = $"http://localhost:8160/v1/profiles/create?name=ApiProfile&workspaceId=-1&screen={Uri.EscapeDataString(screen)}";
88+
// Результат: ...?screen=HD%2B
89+
```
90+
**Python (Requests):** Библиотека `requests` делает это автоматически, если передавать параметры словарем.
91+
``` Python
92+
params = {'screen': 'HD+'}
93+
response = requests.get('http://localhost:8160/v1/profiles/create', params=params)
94+
# Библиотека сама преобразует это в HD%2B
95+
```

i18n/en/docusaurus-plugin-content-docs-zennobrowser/current/zb-public-API/getting-started-with-the-zennobrowser-api.mdx

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,52 @@ The API Token is required to execute all requests. It can obtained as follows:
4747
1. After deleting the token, it will continue functioning within 1.5-2 hours;
4848
2. After token has expired, it will cease to function;
4949
3. If you have lost a previously created token, you can create a new one.
50+
51+
## **Parameter Encoding (URL Encoding)**
52+
53+
### **Important: Passing special characters in parameter values**
54+
55+
If you construct HTTP requests manually (using `HttpClient`, `fetch`, `curl`, etc.), you **must URL-encode parameter values**.
56+
57+
This is especially important for parameters like `screen=HD+`.
58+
If the `+` character is not encoded, the server will interpret it as a **space**, which will result in an error.
59+
60+
**Example for `screen=HD+`**
61+
62+
* **Incorrect:** `.../create?screen=HD+`
63+
* **Correct:** `.../create?screen=HD%2B`
64+
65+
### Commonly Used Characters
66+
67+
For the API to work correctly, the following characters **must be encoded when they are part of parameter values**.
68+
69+
Encode these characters **only if they are part of the actual data (values)**, not as URL syntax.
70+
71+
| Character | Description | Encoded |
72+
| ----- | ----- | ----- |
73+
| `+` | Plus sign (e.g. `HD+`) | `%2B` |
74+
| (space) | Space | `%20` |
75+
| `&` | Ampersand (parameter separator) | `%26` |
76+
| `=` | Equals sign | `%3D` |
77+
| `?` | Question mark | `%3F` |
78+
| `/` | Slash | `%2F` |
79+
| `:` | Colon | `%3A` |
80+
81+
### Implementation Examples
82+
83+
**C# (HttpClient)**
84+
85+
Instead of manually concatenating strings, use `Uri.EscapeDataString()` for parameter values that may contain special characters.
86+
``` csharp
87+
string screen = "HD+";
88+
string url = $"http://localhost:8160/v1/profiles/create?name=ApiProfile&workspaceId=-1&screen={Uri.EscapeDataString(screen)}";
89+
// Result: ...?screen=HD%2B
90+
```
91+
**Python (Requests)**
92+
93+
The `requests` library automatically handles URL encoding when parameters are passed as a dictionary.
94+
``` Python
95+
params = {'screen': 'HD+'}
96+
response = requests.get('http://localhost:8160/v1/profiles/create',params=params)
97+
# The library automatically converts this to HD%2B
98+
```

0 commit comments

Comments
 (0)