Home > SYS_ClientUrl > request
SYS_ClientUrl.request() method
Make an immediate request
Signature
function request(
url: string,
method?: 'GET' | 'POST' | 'HEAD' | 'PUT' | 'DELETE' | 'PATCH',
data?: string | Blob | FormData | URLSearchParams,
options?: { headers?: undefined | { [key: string]: any }; integrity?: undefined | string },
succeedCallFn?: (data: Response) => void | Promise<void>,
): Promise<Response>;2
3
4
5
6
7
Parameters
Parameter | Type | Description |
|---|---|---|
url | string | Request URL |
method | 'GET' | 'POST' | 'HEAD' | 'PUT' | 'DELETE' | 'PATCH' | (Optional) Request method |
data | string | Blob | FormData | URLSearchParams | (Optional) Data to be sent with the request, which can be direct data or a URLSearchParams object. If the method is |
options | { headers?: undefined | { [key: string]: any }; integrity?: undefined | string } | (Optional) Request options |
succeedCallFn | (data: Response) => void | Promise<void> | (Optional) Function to call back after the request succeeds |
Returns
Promise<Response>
The return result of Fetch
Remarks
Please note that the requested site must allow cross-origin resource sharing (CORS); otherwise, the API will always return an error result.
developer.mozilla.org/docs/Web/HTTP/CORS | Cross-Origin Resource Sharing (CORS) - MDN}.
Note: This API requires the user to enable the extension external interaction permission, if not enabled, it will always throw Error
Example
// 1. 发起 GET 请求(本例用本机桥接地址演示,实际使用时换成自己的服务地址)
const response = await eda.sys_ClientUrl.request('http://localhost:49620/health', 'GET');
// 2. 读取响应状态码
console.log('状态码:', response.status);
// 3. 读取响应内容(Response 是标准 fetch 返回值,用法与浏览器一致)
const body = await response.text();
console.log('响应内容:', body);2
3
4
5
6
7
8
9