Skip to content

Commit 109969d

Browse files
committed
更新JSON提交示例,使用匿名对象方式简化代码
1 parent 0d29ada commit 109969d

2 files changed

Lines changed: 12 additions & 10 deletions

File tree

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,13 @@ var loginResponse = postRequest.GetResponse();
128128

129129
// 4. 发送JSON数据的POST请求
130130
var jsonRequest = new HttpRequestClass();
131-
// 设置请求头为JSON
132-
jsonRequest.Set().HeadersArray["Content-Type"] = "application/json";
133-
// JSON字符串数据
134-
string jsonData = "{\"name\":\"测试\",\"age\":25}";
131+
// 直接使用匿名对象发送JSON请求(会自动设置Content-Type为application/json)
135132
// 发送请求
136-
jsonRequest.Open("https://api.example.com/users", HttpMethod.Post).Send(jsonData);
133+
jsonRequest.Open("https://api.example.com/users", HttpMethod.Post).Send(new
134+
{
135+
name = "测试",
136+
age = 25,
137+
});
137138
var userResponse = jsonRequest.GetResponse();
138139

139140
// 5. 发送异步请求示例

docs/README_EN.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,13 @@ var loginResponse = postRequest.GetResponse();
128128

129129
// 4. Send POST request with JSON data
130130
var jsonRequest = new HttpRequestClass();
131-
// Set request header to JSON
132-
jsonRequest.Set().HeadersArray["Content-Type"] = "application/json";
133-
// JSON string data
134-
string jsonData = "{\"name\":\"Test\",\"age\":25}";
131+
// Send JSON request directly using anonymous object (automatically sets Content-Type to application/json)
135132
// Send request
136-
jsonRequest.Open("https://api.example.com/users", HttpMethod.Post).Send(jsonData);
133+
jsonRequest.Open("https://api.example.com/users", HttpMethod.Post).Send(new
134+
{
135+
name = "Test",
136+
age = 25,
137+
});
137138
var userResponse = jsonRequest.GetResponse();
138139

139140
// 5. Asynchronous request example

0 commit comments

Comments
 (0)