Link to home
Start Free TrialLog in
Avatar of BlackMan
BlackMan

asked on

I need to receive XML from a C# program using HTTP POST

Hi,

A program written in C# wants to send me some data in XML format using HTTP POST so I need a HTTP server implementation to handle that.
It seems like Indy TidHttpServer / OnCommandOther could be used to it but since I'm under a very tight schedule, I really don't have the time to investigate it.

A solution that shows how to use Indy to receive a XML document from a C# client using HTTP POST and save it to a file, is what I'm looking for..

I'm using Delphi 6 and would prefer to use the Indy version supplied with that if possible.

Cheers,
Lars
Avatar of atul_parmar
atul_parmar
Flag of India image

1. Drop a TidHttpServer component
2. On the form create event set
    IdHTTPServer1.DefaultPort := 80; // the port where your C# app will connect
    IdHTTPServer1.Active := True;
3. write the following code to the IdHTTPServer1CommandGet event of TidHttpServer component
   var
     xmlText : TStringList;
   begin
    if ARequestInfo.Command = 'GET' then
    begin
      xmlText := TStringList.Create;
      xmlText.LoadFromFile(XMLFileName);
      AResponseInfo.ContentText := xmlText.Text;
      xmlText.Free;
    end;
  end;

Avatar of BlackMan
BlackMan

ASKER

Hi,

You solution is the other way around - someone GETTING a XML file from me.
I need to receive the XML (via POST) from someone else.

Cheers,
Lars
Well, do this.

var
  s : TStringList;
begin
  IdHTTP1.Port := 80; // port number of the server
  IdHTTP1.Connect;
  s := TStringList.Create;
  memo1.Text := IdHTTP1.Post('localhost', s);
  s.Free;
end;
Sorry, it is still not what I'm looking at..

I need my program to act as a webserver RECEIVING xml-files, so I need to somehow hook into the POST event and save the xml data that are sent to me.
Actually, you can use your last code as a test client when you have made the other end :)

Cheers,
Lars
ASKER CERTIFIED SOLUTION
Avatar of atul_parmar
atul_parmar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ah, I'll check that out - I got confused by the name of the event (OnCommandGet), thought it would only fire on GET operations..

I'll let you know later, thanks..

Cheers,
Lars
Just tried it..

RequestInfo.Command just contains a "/" but it seems like my XML is in RequestInfo.UnparsedParams. Unfortunately, it is "encoded" like this
"'<'#0'?'#0'x'#0'm'#0'l'#0' '#0'v'#0'e'#0'r'#0's'#0'i'#0'o'#0'n'#0'='#0'"'#0'1'#0'.'#0'0'#0'"'#0' '#0'e'#0'n'#0'c'#0'o'#0'd'#0'i'#0'n'#0'g'#0'='#0'"'#0'U'#0'T'#0'F'#0'-'#0'8'#0'"'#0'?'#0'>'#0'<'#0'B'#0'a'#0's'#0'e'#0' '#0'/'#0'>'#0"

Don't know if that is unicode but how do I get the "plain" XML out of it  - and is UnparsedParams really the way to go?


Cheers,
Lars
It will be in RequestInfo.Document
The RequestInfo.UnparsedParams contains the url encoded http header. to get the plain text header info use params property.
I'm sorry, I made a mistake in my previous mail..
RequestInfo.Document = '/'  (command is 'POST' of course)

Let me check the code from the C# guy to make sure that they actualle are submitting something valid.

Cheers,
Lars
atul_parmar,

Sorry for the late reply - have been on vacation. I'll work with the C# guys next week and let you know the result.

Cheers,
Lars