Chuyển tới nội dung chính

Đọc tệp (RAW)

Đọc theo luồng

  • Mô tả giao diện

    GET /read_file?filename=[tên tệp được mã hóa URL] HTTP/1.1
    • Truy vấn tùy chọn md5=1: thêm Content-MD5 (Base64) vào tiêu đề phản hồi
  • Phản hồi có thể có

    • Thành công: HTTP 200, nội dung phản hồi là byte thô của tệp, không mã hóa Base64
    • Thất bại:
      • HTTP 404 + {"message":"File not found"} (tệp không tồn tại hoặc thiếu filename)
      • HTTP 415 + {"message":"File is a directory"} (đường dẫn trỏ đến thư mục)
  • Ví dụ Python 3.x để đọc tệp kịch bản theo luồng, yêu cầu requests:

    # -*- coding: utf-8 -*-
    import requests

    with requests.get(
    "http://192.168.31.72:46952/read_file",
    params={"filename": "lua/scripts/123.lua", "md5": 1},
    stream=True,
    timeout=30,
    ) as r:
    r.raise_for_status()
    with open("r:/123.lua", "wb") as f:
    for chunk in r.iter_content(chunk_size=8192):
    if chunk:
    f.write(chunk)
    print("Content-MD5:", r.headers.get("Content-MD5"))

Đọc bằng Base64

  • Mô tả giao diện

    POST /read_file HTTP/1.1

    {"filename":"tên tệp"}
  • Phản hồi có thể có

    {"code":0,"message":"操作成功","data":"nội dung tệp được mã hóa Base64"}
    {"code":4,"message":"无法读取文件"}
    {"code":8,"message":"参数错误"}
  • Ví dụ Python 3.x để đọc tệp kịch bản từ thiết bị, yêu cầu requests:

    # -*- coding: utf-8 -*-
    import base64
    import requests

    resp = requests.post(
    "http://192.168.31.72:46952/read_file",
    json={"filename": "lua/scripts/123.lua"},
    timeout=30,
    )

    print(resp.status_code, resp.reason) # 200 OK khi thành công
    if resp.status_code == 200:
    ret = resp.json()
    print(ret.get("message"))
    if ret.get("code") == 0:
    print(base64.b64decode(ret["data"]).decode("utf-8"))
    else:
    print(resp.text)

Lưu ý

  • Thư mục gốc của cả hai phương thức đọc là /var/mobile/Media/1ferver/
  • Điểm cuối đọc theo luồng khả dụng trong các phiên bản sau 2025-07-11