-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost-json.pwn
More file actions
39 lines (33 loc) · 1.19 KB
/
post-json.pwn
File metadata and controls
39 lines (33 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// post-json.pwn — POST a JSON body using the JSON builder.
//
// Demonstrates:
// * Staging a JSON payload with https_jsonf (Content-Type is set automatically).
// * Submitting a POST with an empty inline body so the staged payload is consumed.
// * A custom header that overrides the builder's default Content-Type if needed.
#include <a_samp>
#include <https_samp>
public OnGameModeInit()
{
// The JSON is validated before being staged.
if (!https_jsonf("{\"player\":\"erick\",\"score\":42}"))
{
print("[example] invalid JSON, request not sent");
return 1;
}
// Optional: a temporary header just for this request.
https_set_header("X-Trace-Id", "example-001");
// Empty "data" tells the plugin to use the staged payload.
https(1, HTTPS_POST, "https://httpbin.org/post", "", "OnPostJson");
return 1;
}
forward OnPostJson(index, response[], status, error);
public OnPostJson(index, response[], status, error)
{
if (error != HTTPS_ERROR_NONE)
{
printf("[example] post %d failed: error=%d", index, error);
return 1;
}
printf("[example] post %d ok: status=%d, %d bytes", index, status, strlen(response));
return 1;
}