Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2006-06-25
11
Medium Priority
?
1,655 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

618 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