๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.internet.socket
12 messages
12 total messages Started by Jan Tue, 05 Jul 2005 10:44
Posting a XML file with HTTP
#3606
Author: Jan
Date: Tue, 05 Jul 2005 10:44
111 lines
4383 bytes
Hello,

I try to post a XML file but get always the error:
Invalid argument to data encode.
What is wrong with the code ?

      TStringList *LIpost = new TStringList;

      HTTP->Response->ContentType = "text/xml";   
      HTTP->Connect(IdTimeoutDefault);
      if (HTTP->Connected())  {
        sSourceFile = "C:\\Temp\\test.xml";
        LIpost->Clear();
        LIpost->LoadFromFile(sSourceFile);
        try  {
          HTTP->Post(PathHttp, LIpost);
         } catch(const Exception &e) {
           ShowMessage("Error encountered during POST: " + e.Message);
         }
      }

And here the XML file:

<schemainstances><schemainstance id="2851" schemamnemonic="product">
  <createdts>05/07/2005 10:26:08 AM</createdts>
		<name>CAMBQQA7D0A</name>
		<locales>
			<locale name="common">
					<foto>
					 <value>Q3702A_190X170.JPG</value>
					</foto>
					<category>
							<value>BQ</value>
					</category>
					<frontpage>
							<value>True</value>
					</frontpage>
					<price>
							<value>0</value>
					</price>
					<priceexcltax>
							<value>0</value>
					</priceexcltax>
					<vatrate>
							<value>21</value>
					</vatrate>
					<group>
							<value>CAM</value>
					</group>
					<rating />
					<backorder>
							<value>False</value>
					</backorder>
			</locale>
			<locale name="nl-be">
					<title>
							<value>Camera BenQ DC E53 4.92M Silver Extra Large 2.5inch
LCD</value>
					</title>
					<shortdescription>
							<value></value>
					</shortdescription>
					<longdescription>
							<value><![CDATA[Digital Camera BenQ DC E53 Extra Large LCD
Total pixels: 5.20 megapixels
Effective Pixels: 4.92 megapixels effective CCD
Image Resolution: 2560 x 1920, 2048 x 1536, 1280 x 960, 640 x 480
Lens: Focus Length: F=5.4~16.2mm
Lens aperture: F2.8 / F4.8
Focusing Range: Macro: 6 cm / Normal: 50 cm to infinity
Digital Zoom: 3.6x
Optical Zoom: 3x
Shutter Speed: 1/2 ~ 1/1000 sec
Flash: Auto /Forced /Flash off /Red-eye reduction /Night Scene 0.5m ~
2.7m
White Balance: Auto / Daylight / Incandescent/Fluorescent 1/
Fluorescent 2 / Cloudy / Manual
Movie Mode: AVI 320x240 pixels, Continuous recording
Self-Timer: 10 seconds, 2 seconds, 10+2 sec
Storage: SD card compatible
File Format: Still image: JPEG (EXIF 2.2), DCF, DPOF
Connectivity: Digital out: USB 1.1 / Audio /Video output / AC Adapter
Power Source: Rechargeable Lithium-ion battery /AC adaptor
LCD: 2.5๏ฟฝ Color LTPS LCD
Weight: 130 g (without battery)
Dimensions (WxDxH): 88.5x24x54.5mm
Voice memo: WAV format, 20 seconds
Included accessories:
Lithium-ion battery x 1 / USB + Power + AV 3 in 1 cable / AC adaptor /
SD memory card (32MB) / Camera pouch / Wrist strap / User๏ฟฝs manual /
Software CD (AP and Driver included)
Limited warranty: 2 years carry-in exchange
Other features:
Superior Lithium-ion Battery: last for at least 370 photos taken
Support ISO up to 200 for good color saturation
Macro Mode: 6cm
32 MB SD card bundled
Built-in microphone and speaker
Distinct 2.5" color LTPS LCD
Despite a diminutive form roughly the height and width of a business
card, the BenQ DC E53 still manages to incorporate a spacious 2.5"
color screens. And compared to ordinary TFT LCDs, these camera's LTPS
LCD offers color that is more vibrant and with
superior saturation. And its lower power consumption gives you longer
battery life for taking and browsing your photographs. The very act of
taking a photograph.
]]></value>
					</longdescription>
			</locale>
	</locales>
</schemainstance></schemainstances>
Re: Posting a XML file with HTTP
#3607
Author: Hans Galema
Date: Tue, 05 Jul 2005 11:16
26 lines
1664 bytes
Jan wrote:

> I try to post a XML file but get always the error:
> Invalid argument to data encode.

What component are you using ?
On which statement do you get the error ?
Do you get the error in the catch block ?

>       TStringList *LIpost = new TStringList;

>           HTTP->Post(PathHttp, LIpost);

Well you are trying to post -the contents of- a TStringList.

> And here the XML file:
> 
> <schemainstances><schemainstance id="2851" schemamnemonic="product">
....
> </schemainstance></schemainstances>

Please first try to post a file or TStringList that only has a line
of five and does not contain CDATA. Is that possible ? Is it
only whith this specific file ?

Hans.
Re: Posting a XML file with HTTP
#3608
Author: Jan
Date: Tue, 05 Jul 2005 11:57
63 lines
2600 bytes
Hans Galema wrote:

> What component are you using ?
> On which statement do you get the error ?
I use Indy version 9.00.10 and BCB 5

> Do you get the error in the catch block ?
No, on the Post method

> 
> >      TStringList *LIpost = new TStringList;
> 
> >          HTTP->Post(PathHttp, LIpost);
> 
> Well you are trying to post -the contents of- a TStringList.
> 
> 
> Please first try to post a file or TStringList that only has a line
> of five and does not contain CDATA. Is that possible ? Is it
> only whith this specific file ?
> 
I have try with a small XML file without CDATA and get thesame error.

I don't think I need to pass a parameter list to the HTTP.
The URL is quite normal:
http://192.168.2.191/synchronize/schemainstance_import.aspx and runs
now on a locat test webserver with the latest .Net framework.

I have also try with a Stream, but no difference.
String PathHttp =
"http://192.168.2.191/synchronize/schemainstance_import.aspx";
TMemoryStream *Astream = new TMemoryStream();
Astream->Clear();
Astream->LoadFromFile("C:\\Temp\\Test.xml");
HTTP->Post(PathHttp, Astream);

And the Test.Xml :

<schemainstances><schemainstance id="2851" schemamnemonic="product">
  <createdts>05/07/2005 01:46:04 PM</createdts>
		<name>CAMBQQA6D1A</name>
		<locales>
			<locale name="common">
					<foto>
					 <value>Q3702A_190X170.JPG</value>
					</foto>
					<category>
							<value>BQ</value>
					</category>
					<frontpage>
							<value>True</value>
					</frontpage>
					<price>
							<value>0</value>
					</price>
			</locale>
			<locale name="nl-be">
					<title>
							<value>Camera BenQ DC E40 4.0M GOLD</value>
					</title>
			</locale>
	</locales>
</schemainstance></schemainstances>
Re: Posting a XML file with HTTP
#3609
Author: Hans Galema
Date: Tue, 05 Jul 2005 13:49
33 lines
1985 bytes
Jan wrote:

>>What component are you using ?

> I use Indy version 9.00.10 and BCB 5

That is a componentsuite which contains many components.
Which do you use here ?

>>Do you get the error in the catch block ?
> 
> No, on the Post method

> I don't think I need to pass a parameter list to the HTTP.

What do you mean with that ?

> The URL is quite normal:
> http://192.168.2.191/synchronize/schemainstance_import.aspx and 

If your error is: "Invalid argument to data encode." then the Post
is probably not done then the URL is not used. Try a non existing URL
and see what happens.

So there is no exeption thrown by Post on that error and ShowMessage()
in  your code is not invoked ? Is there a return-value for the Post
method that you have to consider ?

You could also tell if this are your first steps with
this component or that you used Post() a lot without problems
on other URL's.

Hans.
Re: Posting a XML file with HTTP
#3610
Author: Remy Lebeau (TeamB)
Date: Tue, 05 Jul 2005 17:20
43 lines
2160 bytes
"Jan" <jan@jlcsoft.com> wrote in message
news:42ca6485@newsgroups.borland.com...

>       HTTP->Response->ContentType = "text/xml";

You should be filling in the Request, not the Response.

>       HTTP->Connect(IdTimeoutDefault);
>       if (HTTP->Connected())  {

This is not the cause of the problem, but you should get rid of that code.
You are not supposed to be doing that.  Post() handles that internally.

>         LIpost->LoadFromFile(sSourceFile);

Rather than using a TStringList, use a TFileStream instead.  Indy does extra
processing on TStrings parameters but not on TStream.  Your XML is going to
get potentially messed up during the Post() if you use a TStringList.

Use this code instead:

    TFileStream *LIpost;
    try
    {
        LIpost = new TFileStream("C:\\Temp\\test.xml", fmOpenRead |
fmShareDenyWrite);
        try
        {
            HTTP->Request->ContentType = "text/xml";
            HTTP->Post(PathHttp, LIpost);
        }
        __finally {
            delete LIpost;
        }
    }
    catch(const Exception &e)
    {
        ShowMessage("Error encountered during POST: " + e.Message);
    }


Gambit
Re: Posting a XML file with HTTP
#3611
Author: Remy Lebeau (TeamB)
Date: Tue, 05 Jul 2005 17:21
14 lines
1317 bytes
"Jan" <jan@jlcsoft.com> wrote in message
news:42ca75b0@newsgroups.borland.com...

> I have try with a small XML file without CDATA and get thesame error.

The content of the XML is irrelavent.  Indy does not process it.

> I have also try with a Stream, but no difference.

Using a stream is exactly what you should be doing.


Gambit
Re: Posting a XML file with HTTP
#3613
Author: Remy Lebeau (TeamB)
Date: Tue, 05 Jul 2005 17:22
13 lines
1341 bytes
"Hans Galema" <notused@notused.nl> wrote in message
news:42ca90d2$1@newsgroups.borland.com...

> That is a componentsuite which contains many components.
> Which do you use here ?

There is only one HTTP client component in Indy - TIdHTTP.  If you don't
know how Indy works, then you should not be answering Indy-related
questions.


Gambit
Re: Posting a XML file with HTTP
#3612
Author: Remy Lebeau (TeamB)
Date: Tue, 05 Jul 2005 17:30
36 lines
1844 bytes
"Jan" <jan@jlcsoft.com> wrote in message
news:42ca6485@newsgroups.borland.com...

> I try to post a XML file but get always the error:
> Invalid argument to data encode.

There is no such error message in Indy, or the VCL in general for that
matter.  Are you sure that the error message isn't actually the following
instead?

    Invalid argument to date encode.

Notice *date* vs. *data*.

What is the actual class type, not the text message, of the exception being
thrown?

    catch(const Exception &e)
    {
        ShowMessage(e.ClassName());
    }

If the error is actually an invalid *date* encoding, then that suggests that
either:

1) you did not specify a valid Request->Date, Request->Expires, or
Request->LastModified value

2) the server sent back a Response->Date, Response->Expires, or
Response->LastModified value that Indy does not understand.

Those are the only date-related values that TIdHTTP uses.


Gambit
Re: Posting a XML file with HTTP
#3614
Author: Hans Galema
Date: Tue, 05 Jul 2005 18:32
23 lines
1894 bytes
Remy Lebeau (TeamB) wrote:

> There is only one HTTP client component in Indy - TIdHTTP.  

Yes. I know. No reason for the OP not to name it. Especially
when asked.

 > If you don't
> know how Indy works, then you should not be answering Indy-related
> questions.

Please do not chase away people that try to help others. I had already
looked at a HTTPCLient example and was amazed that Jan used Response.
Besides, there is much more in the OP's post then Indy. Until now I
had more questions for the OP then answers. That is my way to help the
OP to formulate/understand a problem.

Even if I had never heard of Indy then still all the remarks and
questions I made in this thread were adequate.

Why do you condemn so fast? Let others live.

Hans.
Re: Posting a XML file with HTTP
#3615
Author: Jan
Date: Tue, 05 Jul 2005 20:48
38 lines
1862 bytes
> There is no such error message in Indy, or the VCL in general for that
> matter.  Are you sure that the error message isn't actually the
> following instead?
> 
>     Invalid argument to date encode.
> 
> Notice date vs. data.
Yes, sorry, it is DATE

> 
> What is the actual class type, not the text message, of the exception
> being thrown?
> 
>     catch(const Exception &e)
>     {
>         ShowMessage(e.ClassName());
>     }
> 
The code don 't execute the catch statement, on the post methode, 0.5
seconds later I get the error.

> If the error is actually an invalid date encoding, then that suggests
> that either:
> 
> 1) you did not specify a valid Request->Date, Request->Expires, or
> Request->LastModified value
Gives nothing when I change this values.
> 
> 2) the server sent back a Response->Date, Response->Expires, or
> Response->LastModified value that Indy does not understand.

Can it be that it is a aspx page .Net framework ?
I check tomorrow with the network administrator for the settings on the
webserver.

Thanks for the tip and help.

Jan
Re: Posting a XML file with HTTP
#3616
Author: Remy Lebeau (TeamB)
Date: Tue, 05 Jul 2005 21:57
17 lines
1624 bytes
"Jan" <jan@jlcsoft.com> wrote in message
news:42caf232@newsgroups.borland.com...

> The code don 't execute the catch statement

The only way that can happen is if you are running your program inside the
IDE debugger, and the debugger is catching the exception before your code
does, displaying a popup message to you, and then when you dismiss the
dielog the exception is passed back to your code but Indy then traps the
exception internally and discards it so that your code never sees it.

Are you actually running your program inside the debugger?  What happens if
you run the program outside the debugger?


Gambit
Re: Posting a XML file with HTTP
#3618
Author: Jan
Date: Wed, 06 Jul 2005 15:41
9 lines
1028 bytes
Problem solved.
In the configuration of the .NET page I have removed the line
"trace=true" and works fine now. I think Indy have a problem with that.

Verry stranges.

Thanks for the help.

Jan
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