Recent

Author Topic: [SOLVED] How to POST a SOAPAction with synapse?  (Read 533 times)

Key-Real

  • Full Member
  • ***
  • Posts: 185
[SOLVED] How to POST a SOAPAction with synapse?
« on: June 08, 2023, 10:14:08 pm »
I think to POST a http request the code is like this !?!

Code: Pascal  [Select][+][-]
  1. {$MODE OBJFPC}{$H+}
  2. uses httpsend;
  3. var
  4. f : text;
  5.         post : string;
  6.         s : string;
  7.         http : THTTPSend;
  8. begin
  9.  
  10.         assignfile(f, 'add.xml');
  11.         reset(f);
  12.         post:= '';
  13.         repeat
  14.                 readln(f, s);
  15.                 post:= post + s + #$0a + #$0d;
  16.         until eof(f);
  17.         close(f);
  18.  
  19.  
  20.         //writeln(post);
  21.  
  22.         http:=THTTPSend.Create;
  23.  
  24.         http.Document.Clear;
  25.     http.Document.Write(Pointer(post)^, Length(post));
  26.     http.MimeType:='text/xml; charset=UTF-8';
  27.  
  28.          if not http.HTTPMethod('POST', 'http://192.168.0.1/upnp/control/WANIPConnection0') then begin
  29.  
  30.  
  31.            
  32.          end;
  33.     writeln(http.ResultCode);
  34.     writeln(http.ResultString);
  35.  
  36.         http.Free;
  37. end.
  38.  


how to POST a SOAP Action?
« Last Edit: June 13, 2023, 10:29:52 pm by Key-Real »

rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: How to POST a SOAPAction with synapse?
« Reply #1 on: June 09, 2023, 12:12:23 am »
Small snippet from my code: (this is for getting the UPnP ports forwarded / GetGenericPortMappingEntry)

(you should already have read the location for the UPnP service URL and the correct ServiceTag (between the servicetag tags).

Note the AddHeader for SOAPAction which you don't have.

Code: Pascal  [Select][+][-]
  1. var
  2.   S, Found: String;
  3.   HTTP: THTTPSend;
  4. begin  
  5.  
  6.   Location := IP_AND_PATH_OF_ROUTER_UPNP_SERVICE;
  7.   ServiceType := SERVICERTPE_BETWEEN_THE_SERVICETYPE_TAGS_IN_SERVICEXML;
  8.  
  9.   S := '';
  10.   S := S + '<?xml version="1.0" encoding="utf-8"?>';
  11.   S := S + '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">';
  12.   S := S + ' <s:Body>';
  13.   S := S + '  <u:GetGenericPortMappingEntry xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1">';
  14.   S := S + '   <NewPortMappingIndex>0</NewPortMappingIndex>';
  15.   S := S + '  </u:GetGenericPortMappingEntry>';
  16.   S := S + ' </s:Body>';
  17.   S := S + '</s:Envelope>';
  18.  
  19.   Response := TStringList.Create;
  20.   HTTP := THTTPSend.Create;
  21.   try
  22.     WriteStrToStream(HTTP.Document, S);
  23.     HTTP.MimeType := 'text/xml; charset="utf-8"';
  24.     HTTP.Headers.Add('SOAPAction: ' + ServiceType + '#GetGenericPortMappingEntry');
  25.     if HTTP.HTTPMethod('POST', Location) then
  26.     begin
  27.       Response.LoadFromStream(HTTP.Document);
  28.       Found := Response.Text;
  29.       writeln(found);
  30.     end;
  31.   finally
  32.     Response.Free;
  33.     HTTP.Free;
  34.   end;
  35. end;

 

TinyPortal © 2005-2018