Hi all
I've got an application that posts data to a website & read pages from the
same site.
I use the following to post the data. I list this function at the bottom.
The current application uses normal http post. The new requirements are that
it should be posted to a secure site. My problem is that the method below
will not work, not event if you change the http to https. I've got some auth
certificates that was issued by the client.
Do any of you know of an easy whay to modify the function below to achieve
this? I don't want to go and spend a lot of money on 3rd party stuff.
Start Code###############################
function UploadXML( Host : string; Port : integer; UploadPath : string; XML
: string; var XMLResult : string ) : boolean;
var
strData: String;
strPostData: String;
Buffer: Pointer;
iTotal: LongWord;
iRead: Integer;
ClientSocket: TClientSocket;
SocketStream : TWinSocketStream;
lstRequest: TStringList;
lstResult: TStringList;
strSecurityKey : string;
begin
Result := false;
GetMEM( Buffer, 64000 );
fillchar( Buffer^, 64000, 0 );
ClientSocket := TClientSocket.Create( Nil );
ClientSocket.ClientType := ctBlocking;
ClientSocket.Host := Host;
//ClientSocket.Host := '10.0.1.2';
ClientSocket.Port := Port;
//ClientSocket.Port := 808;
SocketStream := TWinSocketStream.Create( ClientSocket.Socket, 60000 );
lstRequest := TStringList.Create;
lstRequest.Sorted := False;
lstResult := TStringList.Create;
lstResult.Sorted := False;
try
try
DebugLog( 'Building http header...' );
lstRequest.Clear;
lstRequest.Add( 'POST http://' + Host + ':' + IntToStr( Port ) +
UploadPath + ' HTTP/1.1' );
lstRequest.Add( 'Host: ' + Host );
lstRequest.Add( 'MIME-Version: 1.0' );
lstRequest.Add( 'Content-type: text/xml; charset="UTF-8" ' );
lstRequest.Add( 'Content-Transfer-Encoding: 8bit' );
lstRequest.Add( 'Content-length: ' + IntToStr( Length( XML ) ) );
lstRequest.Add( '' );
lstRequest.Add( XML );
DebugLog( 'Connecting to remote server...' );
ClientSocket.Open;
DebugLog( 'Connected to remote server.' );
strData := lstRequest.Text;
DebugLog( 'Sending http post...' );
SocketStream.Write( strData[1], Length( strData ) );
DebugLog( 'Waiting for result...' );
SocketStream.WaitForData( 60000 );
DebugLog( 'Reading result...' );
if ClientSocket.Socket.Connected then
begin
lstResult.Clear;
iTotal := 0;
repeat
iRead := SocketStream.Read( Ptr( DWORD( Buffer ) + iTotal )^,
64000 - iTotal );
iTotal := iTotal + DWORD( iRead );
until iRead = 0;
end;
DebugLog( 'Closing connection...' );
ClientSocket.Close;
lstResult.Text := PChar( Buffer );
FillChar( Buffer^, 64000, 0 );
XMLResult := lstResult.Text;
Result := true;
Sleep( 1000 );
if Settings.General_DebugLog then
begin
if ForceDirectories( IncludeTrailingBackslash( ExtractFilePath(
ParamStr( 0 ) ) ) + 'XML_In' ) then
begin
strData := IncludeTrailingBackslash( ExtractFilePath( ParamStr( 0
) ) ) + 'XML_In\In_' + FormatDateTime( 'yyyymmddhhnnsszzz', Now ) + '.txt';
lstResult.SaveToFile( strData );
end;
if ForceDirectories( IncludeTrailingBackslash( ExtractFilePath(
ParamStr( 0 ) ) ) + 'XML_Out' ) then
begin
lstResult.Text := XML;
strData := IncludeTrailingBackslash( ExtractFilePath( ParamStr( 0
) ) ) + 'XML_Out\Out_' + FormatDateTime( 'yyyymmddhhnnsszzz', Now ) +
'.txt';
lstResult.SaveToFile( strData );
end;
end;
except
on E:Exception do
begin
Result := false;
ErrorLog( 'Error uploading XML with message: ' + E.Message );
end;
end;
finally
if Assigned( SocketStream ) then SocketStream.Free;
if Assigned( ClientSocket ) then ClientSocket.Free;
if Assigned( lstResult ) then lstResult.Free;
if Assigned( lstRequest ) then lstRequest.Free;
FreeMEM( Buffer, 64000 );
end;
end;
End Code##############################
Thanks
Riaan Stander
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi