Skip to main content

HTTPConnection.PostAsync

PostAsync

Syntax

PostAsync(<HTTPRequest>, <OutputFileName>)

Parameters

<HTTPRequest> (required)

Type: HTTPRequest. Query sent to the server.

<OutputFileName> (optional)

Type: String. If it is not set, then the response body can be obtained using the HTTPResponse object. If it is not set, then the response body can be obtained using the HTTPResponse object.

Returned value

Type: Promise. The promise result is an object of the HTTPResponse type.

Description

Sends data to the specified address for processing using the POST HTTP request.

Availability

Thin client, mobile client, thick client, mobile application (client).

Note

Consider that in the web client, a request can only be sent to the same domain where the web client is published, or to a domain that has no CORS restrictions on accepting a request from the web client. Otherwise, an exception will be thrown. If the web client is published over HTTPS, the request can only be sent using a secure connection. Otherwise, an exception will be thrown.

Example

// initialize object for writing XML

RequestFileName = GetTempFileName();
RecordObject = New XMLWriter;
XMLWriterSettings = New XMLWriterSettings("windows-1251", , False);
RecordObject.OpenFile(RequestFileName, XMLWriterSettings);
RecordObject.WriteXMLDeclaration();

// display the Request root element

RecordObject.WriteStartElement("Request");

// display the ClientInfo element

RecordObject.WriteStartElement("ClientInfo");
RecordObject.WriteAttribute("email", SenderAddress);
RecordObject.WriteEndElement();

If CertificateFileName \<\> Undefined Then

    // encode the certificate to Base64

    DigData.Read(CertificateFileName);
    BaseCertificateFile64 = DigData.GetBaseString64();

    // display the Certificate element

    RecordObject.WriteStartElement("Certificate");
    RecordObject.WriteText(BaseCertificateFile64);
    RecordObject.WriteEndElement();

EndIf;

If ScrambledContainerFileName \<\> Undefined Then

    // encode encrypted container to Base64

    DigData.Read(ScrambledContainerFileName);
    BaseScrambledContainerFile64 = DigData.GetBaseString64();

    // display the Data element

    RecordObject.WriteStartElement("Data");
    RecordObject.WriteText(BaseScrambledContainerFile64);
    RecordObject.WriteEndElement();

EndIf;

// writing end for the root element

RecordObject.WriteEndElement();

RecordObject.Close();

OnLineCheckServerAddress = "onlinefc.taxcom.ru";
ResourceAtServer = "/online_fc/online_fc.dll" + ?(GetCertificate, "?IncludeCertificate", "");

// set connection with server

Try
    Joining = New HTTPConnection(OnLineCheckServerAddress, , , , Proxy);
Except
    Message("Couldn't connect to online check server:"
        + Chars.LF + ErrorInfo().Description, MessageStatus.Important);
    Return;
EndTry;

// send request

Try
    HTTPRequest = New HTTPRequest(ResourceAtServer);
    HTTPRequest.SetBodyFileName(RequestFileName);
    Result  = Joining.Post(HTTPRequest);
    Joining = Undefined;
    If Result.StatusCode \> 299 Then
       Message("Status code " + Result.StatusCode + ". Check was not performed.");
    EndIf;
Except
    Message(ErrorInfo().Description, MessageStatus.Important);
EndTry;

Translation

Русская версия: HTTPСоединение.ОтправитьДляОбработкиАсинх (HTTPConnection.PostAsync)