You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

请求提供RobotFramework中携带Base64内容的POST请求示例

Robot Framework POST Request Example with JSON Body

Got it, let's put together a straightforward Robot Framework example to send that POST request with your specified JSON payload. I'll include all the necessary parts and explain key bits so you can adapt it to your actual API endpoint.

First, you'll need the RequestsLibrary – it's the go-to for HTTP requests in Robot Framework. Make sure it's installed (you can run pip install robotframework-requests if you haven't already).

Here's the complete test case:

*** Settings ***
Library    RequestsLibrary

*** Test Cases ***
Send POST Request with Base64 File Content
    # Step 1: Create a reusable session (cuts down on redundant connection setup)
    Create Session    file_upload_session    https://your-actual-api-domain.com
    
    # Step 2: Build the payload dictionary - plug in your real Base64 string for Content
    ${request_payload}    Create Dictionary    
    ...    Content=PD94bWwgdmVyc...F
    ...    UserId=user@mail.com
    ...    FileName=Test.txt
    
    # Step 3: Convert the dictionary to a proper JSON string
    ${json_payload}    Convert To Json    ${request_payload}
    
    # Step 4: Send the POST request with JSON content type header
    ${response}    Post Request    file_upload_session    /your-api-endpoint-path
    ...    data=${json_payload}
    ...    headers={"Content-Type": "application/json"}
    
    # Step 5: Verify the request succeeded (adjust status code to match your API's success response)
    Should Be Equal As Integers    ${response.status_code}    200
    
    # Optional: Log the response to debug if needed
    Log    API Response: ${response.json()}    INFO

Key Notes:

  • Replace https://your-actual-api-domain.com and /your-api-endpoint-path with your real API's base URL and endpoint path.
  • The Content value is your Base64-encoded file string – just swap out the placeholder with your full encoded content.
  • We use Convert To Json to turn the Robot Framework dictionary into a valid JSON string, which the API expects.
  • The headers parameter ensures the API knows we're sending JSON data – don't skip this, otherwise your payload might be parsed incorrectly.

If you need to handle things like authentication (e.g., bearer tokens), you can add that to the session headers when creating the session, like:

Create Session    file_upload_session    https://your-actual-api-domain.com    headers={"Authorization": "Bearer YOUR_TOKEN"}

内容的提问来源于stack exchange,提问作者chokachi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.28 22:27:34