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

Python新手求助:如何发送text/x-gwt-rpc类型的POST请求并解析网站

Handling GWT-RPC POST Requests in Python for kekeke.cc

Hey there! As someone who's worked through GWT-RPC requests before, let's break this down step by step so you can get up and running as a Python newbie. GWT-RPC (Google Web Toolkit Remote Procedure Call) uses a strict, custom format for requests and responses—so we need to replicate that exactly to make it work.

Step 1: Understand the GWT-RPC Request Structure

First, let's unpack the payload you shared:

7|0|4|https://kekeke.cc/com.liquable.hiroba.home.gwt.HomeModule/|53263EDF7F9313FDD5BD38B49D3A7A77|com.liquable.hiroba.gwt.client.square.IGwtSquareService|getNoOfCrowd|1|2|3|4|0|

This string is a standard GWT-RPC request, where each |-separated section means:

  • Protocol version (7)
  • Request flags (0)
  • Number of registered service methods (4)
  • Base URL of the GWT module
  • A security token (this might change over time—if your requests fail later, re-scrape this from a fresh browser request)
  • The full class name of the remote service interface
  • The method you're calling (getNoOfCrowd)
  • Placeholders for method parameters (empty here)

The critical thing: send this payload exactly as-is (unless the token updates) because GWT-RPC is super picky about formatting.

Step 2: Build the POST Request with Python

We'll use the requests library—it's beginner-friendly and perfect for this task. If you don't have it installed yet, run:

pip install requests

Here's a complete code example to replicate your request:

import requests

# Target endpoint from your request details
url = "https://kekeke.cc/com.liquable.hiroba.gwt.server.GWTHandler/squareService"

# The exact payload you captured
payload = "7|0|4|https://kekeke.cc/com.liquable.hiroba.home.gwt.HomeModule/|53263EDF7F9313FDD5BD38B49D3A7A77|com.liquable.hiroba.gwt.client.square.IGwtSquareService|getNoOfCrowd|1|2|3|4|0|"

# Request headers matching what you provided (add cookies if the site requires login)
headers = {
    "Content-Type": "text/x-gwt-rpc; charset=utf-8",
    "Host": "kekeke.cc",
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0"
}

try:
    # Send the POST request
    response = requests.post(url, data=payload, headers=headers)
    
    # Raise an error if the request failed (e.g., 403, 500)
    response.raise_for_status()
    
    print("Request successful! Raw response:")
    print(response.text)
except requests.exceptions.RequestException as e:
    print(f"Oops, request failed: {e}")

Key Notes:

  • Security Token: That long hex string (53263EDF...) is tied to your browser session. If you get a 403 Forbidden error, re-capture this token using Chrome DevTools or Firefox Network Monitor from a fresh request.
  • Cookies: If the site requires you to be logged in, add a Cookie header to the headers dict with your session cookies (also captured from your browser's dev tools).

Step 3: Parsing the GWT-RPC Response

The response will also be in text/x-gwt-rpc format. A successful response might look like this:

//OK[0,1,["42"],0,7]

To turn this into usable Python data, we can strip the prefix and parse the JSON-like structure:

def parse_gwt_response(response_text):
    # Remove the GWT-RPC-specific prefix
    if response_text.startswith("//OK"):
        clean_response = response_text[4:]
        # Parse the string as a Python list (it's compatible with literal_eval)
        import ast
        return ast.literal_eval(clean_response)
    return response_text

# Use this function after getting the response
parsed_data = parse_gwt_response(response.text)
print("\nParsed response data:")
print(parsed_data)

This will give you a Python list containing the data returned by getNoOfCrowd (like the number of users in the crowd, which the method name hints at).

Troubleshooting Tips

  • 403 Forbidden: Double-check the security token and make sure you're sending all required cookies.
  • Empty Response: The site might have rate limiting—try adding a small delay between requests with time.sleep(2) or ensure your User-Agent matches your browser exactly.
  • Invalid Payload Errors: Re-capture the request from your browser to confirm you haven't missed any characters or updated values.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 12:31:51