Monu Tools

Chuyển đổi cURL sang fetch

Chuyển một lệnh curl thành mã JavaScript fetch tương đương, hoàn toàn trong trình duyệt của bạn.

Cách dùng cURL sang fetch

  1. 01

    Dán một lệnh curl.

  2. 02

    Mã fetch tương đương được tạo tức thì.

  3. 03

    Sao chép JavaScript vào dự án của bạn.

Turn curl into fetch

A converter that turns a curl command into equivalent JavaScript fetch code, parsing the method, URL, headers and body so you get a ready-to-use request instead of translating it by hand.

It is a common need: API docs and tools like browser devtools give you a curl command, but your app is written in JavaScript. This bridges the two so you can paste curl and get fetch.

It runs locally in your browser, so your command, including any tokens or credentials in the headers, never leaves your device.

Flags it understands

It understands the common flags: -X for the method, -H for headers, -d and its variants for the body, -u for basic auth, plus -A for the user agent and -b for cookies. A data flag implies POST, matching how curl behaves.

Multi-line commands

Multi-line commands work as-is. Backslash line continuations are joined automatically, so you can paste a command exactly as it appears in documentation without cleaning it up first.

Ready-to-run output

The output is a fetch call with the method, headers and body filled in, which you can drop into your code and await like any other fetch.

Câu hỏi thường gặp

Những cờ curl nào được hỗ trợ?

Những cờ phổ biến: -X cho phương thức, -H cho header, -d và các biến thể của nó cho body, -u cho basic auth, cùng -A và -b. Một cờ dữ liệu ngụ ý POST.

Lệnh của tôi có được gửi đến máy chủ không?

Không. Việc chuyển đổi chạy hoàn toàn trong trình duyệt của bạn, nên lệnh của bạn và bất kỳ token nào trong đó không bao giờ rời khỏi thiết bị.

Nó có xử lý các lệnh nhiều dòng không?

Có. Các dấu gạch chéo ngược nối dòng được nối tự động, nên bạn có thể dán một lệnh đúng như nó xuất hiện trong tài liệu.

Nguồn

Nhúng công cụ này

Thêm công cụ này vào trang web của riêng bạn. Sao chép đoạn mã bên dưới; nó tự động cập nhật.

<iframe src="https://monu.tools/embed/vi/curl-to-fetch" width="100%" height="640" style="border:1px solid #e5e5e5;border-radius:12px;max-width:680px" loading="lazy" title="Monu Tools"></iframe>

Công cụ liên quan