#include <amxmodx>
#include <grip>
public plugin_init() {
makeRequest();
}
makeRequest() {
new GripBody:body = grip_body_from_string("{^"title^": ^"foo^", ^"body^": ^"bar^", ^"userId^": 1}");
new GripRequestOptions:options = grip_create_default_options();
grip_options_add_header(options, "Content-Type", "application/json");
grip_options_add_header(options, "User-Agent", "Grip");
grip_request("http://jsonplaceholder.typicode.com/posts", body, GripRequestTypePost, "HandleRequest", options);
grip_destroy_body(body);
grip_destroy_options(options);
}
public HandleRequest() {
new GripResponseState:responseState = grip_get_response_state();
if (responseState == GripResponseStateError) {
return;
}
new GripHTTPStatus:status = grip_get_response_status_code();
if (status != GripHTTPStatusCreated) {
return;
}
new response[512];
grip_get_response_body_string(response, charsmax(response));
server_print("Response is %s", response);
}