Solved

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

Posted on 2006-06-25
11
1,602 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
Independent Software Vendors: 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 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
 
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

Technology Partners: 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!

Question has a verified solution.

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

Suggested Solutions

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

739 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