Jump to content

httpServer generate error


MOGSY

Recommended Posts

Hi

I am using an idHttpServer to communicate with external apps. After receiving any message UniGui does not recognising any of the forms or frames.

Please have a look at the attached sample program. I have included a test client "MDC_ClientTester.exe" which will send a JSON string to server on port 9290.

The communication is fine. except after receiving a message UniGui gets confused.

I appreciate any help or suggestion to overcome this issue please.

Thank you.

Test.7z

Link to comment
Share on other sites

Hi,

Your method of handling an external http request is not correct for a uniGUI server project.

Do it this way:

Use UniGUIServerModuleHTTPCommand event to handle json requests.

procedure TUniServerModule.UniGUIServerModuleHTTPCommand(
  ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo;
  var Handled: Boolean);
 

I hope the following example code helps: 
  if ARequestInfo.URI = URI_device_getcommand then
  begin

  Handled := True; // SET. true THIS IS IMPORTANT

  the rest fo the code is a sample:

 

    DevicePostString := nil;
    DeviceJSon := nil;
    CommandJSon := nil;
    LConnection := nil;
    LDevice := nil;
    try


      DevicePostString := TStringStream.Create('');
      DevicePostString.CopyFrom(ARequestInfo.PostStream, ARequestInfo.PostStream.Size);
      DeviceJSon := TJSonObject.ParseJSONValue(DevicePostString.DataString);
      if DeviceJSon.TryGetValue<String>(JSON_PATH_DeviceCode, LDeviceCode) then
      begin
        LDeviceStatusInt := 0;
        LPowerOnTime := 0;
        LPowerOnMinutes := 0;

        DeviceJSon.TryGetValue<String>(JSON_PATH_MACAddress, LMACAddress);
        DeviceJSon.TryGetValue<Integer>(JSON_PATH_DeviceStatus, LDeviceStatusInt);
        DeviceJSon.TryGetValue<Integer>(JSON_PATH_PowerOnMinutes, LPowerOnMinutes);
        DeviceJSon.TryGetValue<String>(JSON_PATH_PowerOnTime, LPowerOnTimeStr);
        TryISO8601ToDate(LPowerOnTimeStr, LPowerOnTime, False);
        LDeviceStatus := TDeviceStatus(LDeviceStatusInt);

        LConnection := TFDConnection.Create(nil);
        LConnection.ConnectionDefName := CONNECTION_DEF_NAME;
        LConnection.Open;

        LDevice := TZDEVICE.CreateWithConnection(LConnection);
        with LDevice do
        begin
 

 

 

 

Edited by Mehmet Emin
fixed typo
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...