Hi Bảo Vũ Bá,
please see the following example:
Code |
---|
Function GetToken() Export
ReturnParameters = New Structure;
ReturnParameters.Insert("Result");
ReturnParameters.Insert("Error", False);
structureBody = New Structure;
structureBody.Insert("clientId", Constants.Alaiko_ClientId.Get());
structureBody.Insert("clientSecret", Constants.Alaiko_ClientSecret.Get());
string_api_PATH = Constants.Alaiko_PathToAPI.Get();
string_api_Key = Constants.Alaiko_API_Key.Get();
HTTPConnection = New HTTPConnection(string_api_PATH,443,,,,, New OpenSSLSecureConnection);
ResourceAddress = "/user/login";
HTTPRequest = New HTTPRequest();
HTTPRequest.ResourceAddress = ResourceAddress;
HTTPRequest.Headers.Insert("Content-Type", "application/json");
HTTPRequest.Headers.Insert("x-api-key", string_api_Key);
JSONWriter = New JSONWriter;
JSONWriter.SetString();
WriteJSON(JSONWriter, structureBody);
resultJSON = JSONWriter.Close();
HTTPRequest.SetBodyFromString(resultJSON);
HTTPResponse = HTTPConnection.Post(HTTPRequest);
If HTTPResponse.StatusCode = 200 Then
JSONReader = New JSONReader;
JSONReader.SetString(HTTPResponse.GetBodyAsString());
ReturnParameters.Result = ReadJSON(JSONReader, False);
Else
ReturnParameters.Result = HTTPResponse.GetBodyAsString();
ReturnParameters.Error = True;
EndIf;
// ReturnParameters.ReturnParameters.Result.AccessToken
Return ReturnParameters;
EndFunction |
Here a POST request is made to some resource. At the same time, we pass request parameters both in the headers of the request itself and in the request body.
Look. If there are any questions, I will answer.