-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcookies-session.pwn
More file actions
45 lines (40 loc) · 1.35 KB
/
cookies-session.pwn
File metadata and controls
45 lines (40 loc) · 1.35 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
40
41
42
43
44
45
// cookies-session.pwn — login then call protected endpoints sharing the session cookie.
//
// Demonstrates:
// * Enabling the cookie store before issuing the login request.
// * Subsequent requests automatically reusing the session cookie.
// * Clearing cookies when logging out.
#include <a_samp>
#include <https_samp>
public OnGameModeInit()
{
https_cookies_enable(true);
// Login: the response Set-Cookie is stored in the jar automatically.
https_form_add("username", "erick");
https_form_add("password", "s3cret");
https(1, HTTPS_POST, "https://httpbin.org/cookies/set/session/abc123", "", "OnLogin");
return 1;
}
forward OnLogin(index, response[], status, error);
public OnLogin(index, response[], status, error)
{
if (error != HTTPS_ERROR_NONE)
{
printf("[example] login failed: error=%d", error);
return 1;
}
// The session cookie is now stored — the next call sends it automatically.
https(2, HTTPS_GET, "https://httpbin.org/cookies", "", "OnSessionCheck");
return 1;
}
forward OnSessionCheck(index, response[], status, error);
public OnSessionCheck(index, response[], status, error)
{
if (error == HTTPS_ERROR_NONE)
{
printf("[example] session check status=%d body=%s", status, response);
}
// Logout flow: wipe the jar.
https_cookies_clear();
return 1;
}