Thread View: borland.public.cppbuilder.internet.web
13 messages
13 total messages
Started by Hamid
Mon, 13 Mar 2006 06:05
sending xml using TIdHTTP
Author: Hamid
Date: Mon, 13 Mar 2006 06:05
Date: Mon, 13 Mar 2006 06:05
2 lines
830 bytes
830 bytes
Is it possible to send xml by TIdHTTP? how?
Re: sending xml using TIdHTTP
Author: Hamid
Date: Mon, 13 Mar 2006 07:42
Date: Mon, 13 Mar 2006 07:42
2 lines
927 bytes
927 bytes
I meant how I can set the content type, encoding and other related settings of the class to show the server how to parse it?
Re: sending xml using TIdHTTP
Author: Hamid
Date: Mon, 13 Mar 2006 07:59
Date: Mon, 13 Mar 2006 07:59
2 lines
980 bytes
980 bytes
Moreover, should I encode the xml before sending (like url)? If yes, how can I encode it? The URLEncode functoin works for URLs only.
Re: sending xml using TIdHTTP
Author: Hans Galema
Date: Mon, 13 Mar 2006 08:15
Date: Mon, 13 Mar 2006 08:15
12 lines
1116 bytes
1116 bytes
Hamid wrote: > Is it possible to send xml by TIdHTTP? Of course. You can send anything. > how? That depends on how the server wants it. What do you consider to be xml ? Hans.
Re: sending xml using TIdHTTP
Author: Hamid
Date: Mon, 13 Mar 2006 08:32
Date: Mon, 13 Mar 2006 08:32
2 lines
1097 bytes
1097 bytes
I mean using the Indy TIdHTTP class and setting the parameters of Request object such as ContentEncoding, ContentType, Method and etc.
Re: sending xml using TIdHTTP
Author: Hans Galema
Date: Mon, 13 Mar 2006 09:24
Date: Mon, 13 Mar 2006 09:24
6 lines
1276 bytes
1276 bytes
Hamid wrote: > I meant how I can set the content type, encoding and other related settings of the class to show the server how to parse it? What do you mean with class ? And how would you send the class then ? Hans.
Re: sending xml using TIdHTTP
Author: Hans Galema
Date: Mon, 13 Mar 2006 12:03
Date: Mon, 13 Mar 2006 12:03
10 lines
1364 bytes
1364 bytes
Hamid wrote: > I meant how I can set the content type, encoding and other related settings of the class to show the server how to parse it? IdHTTP->Request->ContentType = whatever you have. What does the server expect ? Encoding ? How did you encode it ? Or how does the server want you to encode it ? Hans.
Re: sending xml using TIdHTTP
Author: Remy Lebeau (TeamB)
Date: Mon, 13 Mar 2006 21:32
Date: Mon, 13 Mar 2006 21:32
13 lines
1376 bytes
1376 bytes
"Hamid" <hrz_mir@Yahoo.com> wrote in message news:4415306d$1@newsgroups.borland.com... > I meant how I can set the content type, encoding and other > related settings of the class to show the server how to parse it? Again, that depends on exactly how the server expects the data to be transmitted in the first place. Please provide more details about what the server is expecting. Gambit
Re: sending xml using TIdHTTP
Author: Remy Lebeau (TeamB)
Date: Mon, 13 Mar 2006 21:32
Date: Mon, 13 Mar 2006 21:32
11 lines
1241 bytes
1241 bytes
"Hamid" <hrz_mir@Yahoo.com> wrote in message news:44153462$1@newsgroups.borland.com... > Moreover, should I encode the xml before sending (like url)? Usually not. But again, that depends on what the server is actually expecting. Gambit
Re: sending xml using TIdHTTP
Author: hamid
Date: Wed, 15 Mar 2006 06:17
Date: Wed, 15 Mar 2006 06:17
2 lines
1562 bytes
1562 bytes
Of course. I posted my xml by filling the parameters of the Post method of TIdHTTP component line by line from <root> to </root>. Since the xml stream contains some special characters, the form of received xml differs from its source. I think it is because of encoding problem in post method. For example suppose the xml contains "<name> hamid + reza </name>" or any utf-8 characters. I hoped that by setting the header parameters of TIdHTTP I could direct the client to parse the content correctly. How can I solve the encoding problem of sending xml via post?
Re: sending xml using TIdHTTP
Author: Remy Lebeau (TeamB)
Date: Wed, 15 Mar 2006 18:02
Date: Wed, 15 Mar 2006 18:02
14 lines
1472 bytes
1472 bytes
"hamid" <hrz_mir@yahoo.com> wrote in message news:4417bf88$1@newsgroups.borland.com... > I posted my xml by filling the parameters of the Post method That is not what I asked you. How does the SERVER expect the data to be formatted? You need to know that in order to configure TIdHTTP properly. There are also several overloaded versions of Post(). You did not say which one you are actually calling. Gambit
Re: sending xml using TIdHTTP
Author: Hamid
Date: Sat, 18 Mar 2006 16:22
Date: Sat, 18 Mar 2006 16:22
4 lines
1709 bytes
1709 bytes
At first thank you for your response. When I use the Post method (Regardless which overloaded method I'm using) it passes the xml content to the server successfully. But the problem arises when I try to parse the received message with a xml parser. The content contains some special characters. For example the first line : <?xml version="1.0" encoding="utf-8"?>. Now I do not know if I use an Encoding / Decoding before and after passing the content to the server? If yes, which encoding method I should use? The URLEncode method encodes only the texts that have the special form of a URL, not a content. Maybe I should pass a proper MetaClass object to the function, but I do not know which?
Re: sending xml using TIdHTTP
Author: Remy Lebeau (TeamB)
Date: Sun, 19 Mar 2006 00:09
Date: Sun, 19 Mar 2006 00:09
82 lines
3643 bytes
3643 bytes
"Hamid" <hrz_mir@Yahoo.com> wrote in message
news:441c41ec$1@newsgroups.borland.com...
> When I use the Post method (Regardless which overloaded method
> I'm using) it passes the xml content to the server successfully.
That is not what you said earlier.
> But the problem arises when I try to parse the received message with a xml
parser.
You did not say anything about that earlier.
> The content contains some special characters. For example the first line :
> <?xml version="1.0" encoding="utf-8"?>. Now I do not know if I use an
> Encoding / Decoding before and after passing the content to the server?
You have to encode the XML before sending it to the server, and decode it
after receiving it. TIdHTTP does not encode/decode it for you.
> If yes, which encoding method I should use?
The XML prolog states the encoding of the XML content - in this case, the
content is encoded with UTF-8 (which is the default encoding for XML
anyway).
> The URLEncode method encodes only the texts that have the special form
> of a URL, not a content.
You should not be using URLEncode() for XML at all, and you should not be
using any Post() method that calls ULREncode() internally (the ones that
take TStrings as an input parameter). Pass your input XML as a TStream, and
then receive the output XML as a TStream. That way, your input data, and
the output data, are not touched by TIdHTTP at all, meaning that they are
transmitted as-is. For example:
TMemoryStream *pInputXML = new TMemoryStream;
try
{
// load pInputXML with your raw UTF-8 encoded XML as needed....
TMemoryStream *pOutputXML = new TMemoryStream;
try
{
IdHTTP1->Request->ContentType = "text/xml";
IdHTTP->Post("http://yoursite.com", pInputXML, pOutputXML);
// use the raw UTF-8 encoded XML from pOutputXML as needed...
}
__finally
{
delete pOutputXML;
}
}
__finally
{
delete pInputXML;
}
Alternatively, since UTF-8 can fit into an AnsiString, you can do the
following instead:
TStringStream *pInputXML = new TStringStream("");
try
{
// load pInputXML with your raw UTF-8 encoded XML as needed....
IdHTTP1->Request->ContentType = "text/xml";
AnsiString sOutputXML = IdHTTP->Post("http://yoursite.com",
pInputXML);
// use the raw UTF-8 encoded XML from sOutputXML as needed...
}
__finally
{
delete pInputXML;
}
Gambit
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads