?
Solved

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

Posted on 2006-06-25
11
Medium Priority
?
1,628 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 1500 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
 
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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month14 days, 2 hours left to enroll

800 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