SendHTTPResponse Method

Send the HTTP response.

Syntax

int SendHTTPResponse(int iConnectionId, int iStatusCode, const QString& qsStatusDescription, const QByteArray& qbaResponseData);

Remarks

This method sends an HTTP response to the HTTP request identified by ConnectionId.

The response status code and description, as well as the response body, are sent to the client using this method. The ConnectionId value should be obtained from the HTTPRequest event.

StatusCode is the three digit HTTP status code to return, for instance 200.

StatusDescription is the text corresponding to the StatusCode. For instance OK.

ResponseBody specifies the body to be sent back to the client (if any).

Code Example (HTTP)


Azurerelaylistener listener = new Azurerelaylistener();
listener.AccessKey = "9oKRDwjl0s440MlLUi4qHxDL34j1FS6K3t5TRoJ216c=";
listener.AccessKeyName = "RootManageSharedAccessKey";
listener.NamespaceAddress = "myrelay.servicebus.windows.net";
listener.HybridConnection = "hc1";

listener.OnHTTPRequest += (s, e) => {
  Console.WriteLine("HTTP Request from " + e.RemoteAddress + ":" + e.RemotePort);
  Console.WriteLine("HTTP Method: " + e.RequestMethod);
  Console.WriteLine("HTTP Request: " + e.RequestData);
  myConnectionId = e.ConnectionId;
};

//Send a response using the ConnectionId value from the HTTPRequest event
listener.SendHTTPResponse(myConnectionId, 200, "OK", myResponseBody);

Error Handling

This method returns a result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message. (Note: This method's result code can also be obtained by calling the GetLastErrorCode() method after it returns.)

Copyright (c) 2022 /n software inc. - All rights reserved.
IPWorks MQ 2020 Qt Edition - Version 20.0 [Build 8155]