Re: IdHTTPClient POST problem

Giganews Newsgroups
Subject: Re: IdHTTPClient POST problem
Posted by:  Remy Lebeau \(Indy Team\) (re…@lebeausoftware.org)
Date: Tue, 13 Apr 2010

"Walters" <amit_walt…@yahoo.co.in> wrote in message
news:A6978E150AABE340amit_walt…@yahoo.co.in...

> there is no HOST and PORT in IdHTTPClient as it is in Indy 8

You are not supposed to be setting those properties manually to begin with.
Post() parses the input URL and updates the properties as needed.

> when I am trying to use POST Function programme become Non-responding no
> message send.

Well, for starters, you are not taking into account that everything in 2009
is now Unicode.  You need to update your code according.

Second, you are using the wrong version of Post() to send XML data.  The
TStrings version is going to encode the data in a way that will break the
XML.  Use the TStream version instead.

> My code is like this it is working in (C++Builder 6 & Indy 8.0.25)

Try this code:

bool __fastcall TMainForm::SendXmlToServer(const String &tXmlData)
{
    bool RetVal;

    try
    {
        TIdHTTP  *HTTPClient= new TIdHTTP(NULL);
        try
        {
            HTTPClient->Request->Accept = "*/*";
            HTTPClient->Request->AcceptLanguage =  "en-us";
            HTTPClient->Request->UserAgent ="Mozilla/4.0 (compatible; MSIE
6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
            HTTPClient->Request->Connection ="Keep-Alive";
            HTTPClient->Request->ContentType ="text/xml; charset=utf-8";

            TMemoryStream *reqStream = new TMemoryStream();
            try
            {
                WriteStringToStream(reqStream, tXmlData,
TIdTextEncoding::UTF8);

                TMemoryStream *resStream = new TMemoryStream();
                try
                {
                    reqStream->Position = 0;
                    HTTPClient->Post("http://"+ServerHost+":"+IntToStr(ServerPort),
reqStream, resStream);
                    resStream->Position = 0;
                    ...
                    RetVal = true;
                }
                __finally
                {
                    delete resStream;
                }
            }
            __finally
            {
                delete reqStream;
            }
        }
        __finally
        {
            delete HTTPClient;
        }
    }
    catch(const Exception &)
    {
        RetVal = false;
    }

    return RetVal;
}

--
Remy Lebeau (Indy Team)

Replies

In response to

IdHTTPClient POST problem posted by Walters on Mon, 12 Apr 2010