Solved

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

Posted on 2006-06-25
11
1,547 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:BlackMan
  • 6
  • 5
11 Comments
 
LVL 10

Expert Comment

by:atul_parmar
ID: 16981943
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;

0
 
LVL 7

Author Comment

by:BlackMan
ID: 16982357
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
0
 
LVL 10

Expert Comment

by:atul_parmar
ID: 16982456
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;
0
 
LVL 7

Author Comment

by:BlackMan
ID: 16982601
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
0
 
LVL 10

Accepted Solution

by:
atul_parmar earned 500 total points
ID: 16983172
Mate the first post will work for you by just changing the GET to POST. e.g.

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
   begin
    if ARequestInfo.Command = 'POST' then
    begin
       ARequestInfo.Document >>>>>>>>> will contain the stuff you need
    end;
  end;
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 7

Author Comment

by:BlackMan
ID: 16983608
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
0
 
LVL 7

Author Comment

by:BlackMan
ID: 16983660
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
0
 
LVL 10

Expert Comment

by:atul_parmar
ID: 16983678
It will be in RequestInfo.Document
0
 
LVL 10

Expert Comment

by:atul_parmar
ID: 16983729
The RequestInfo.UnparsedParams contains the url encoded http header. to get the plain text header info use params property.
0
 
LVL 7

Author Comment

by:BlackMan
ID: 16984240
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
0
 
LVL 7

Author Comment

by:BlackMan
ID: 17204628
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
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now