File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -128,12 +128,13 @@ var loginResponse = postRequest.GetResponse();
128128
129129// 4. 发送JSON数据的POST请求
130130var 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+ });
137138var userResponse = jsonRequest .GetResponse ();
138139
139140// 5. 发送异步请求示例
Original file line number Diff line number Diff line change @@ -128,12 +128,13 @@ var loginResponse = postRequest.GetResponse();
128128
129129// 4. Send POST request with JSON data
130130var 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+ });
137138var userResponse = jsonRequest .GetResponse ();
138139
139140// 5. Asynchronous request example
You can’t perform that action at this time.
0 commit comments