Board index » delphi » Base64 decode

Base64 decode


2006-09-08 01:45:25 AM
delphi176
Indy 10.0.76
D7 Pro
I'm trying to integrate the XML online tools for UPS. Unlike Fedex, whose
online support was very prompt, UPS is quite slow and not very helpful.
The abbrieviated process is like this: Send an XML file via a HTTP POST
request using an idHTTP component. Then UPS sends back an XML file with a
<GraphicImage>tag that contains a Base64 encoded set of instructions to
send to a Zebra label printer.
My problem is a bunch of extraneous "junk" I get back in the encoded tag.
See below for the raw data. When I decode using an idDecodeMIME component,
the end of the data is truncated about where all the "/////" start (near the
end of the data).
First I want to make sure the return value from a POST does not go through
any transformation that could cause some kind of change to the data UPS is
sending back. My POST looks like this:
XMLReply.XML.Clear;
XMLReply.XML.Add( idHTTP1.Post(
'https://wwwcie.ups.com/ups.app/xml/ShipConfirm', MS ));
where MS is a TMemoryStream containing the XML I am POSTing.
And second, there don't appear to be any decode options except the FillChar
in the idDecodeMIME, but am I missing something? When I use Base64 decode
tools on the web, I get similar results.
Thanks for any pointers,
Rick
Raw Base64 data returned:
STgsQSwwMDEKSTgsQSwwMDEKT0QKcTc5NQpRMTYwMCwyNApTMgpEMTAKSkYKTgpiMTMsNDI5LE0sIjAwMyw4NDAsODAzMDIsMDAwMCxbKT4eMDEdOTYxWjkzNTM2MTgzHVVQU04dOTUzRTc5HjA3UCNcDSxXKklLJzMqKC1TQThDUi5NHTlNVSQqLlwiSDBDSjhMSVgvMzRMNlgjU1wNHgQiCkExNyw3LDAsMiwxLDEsTiwiU0VFRFMgQlkgREVTSUdOIElOQyIKQTE3LDI0LDAsMiwxLDEsTiwiNDM5OSBNQ0RFUk1PVFQgUk9BRCIKQTE3LDQxLDAsMiwxLDEsTiwiTUFYV0VMTCAgQ0EgOTU5NTUiCkE2MiwxNjQsMCw0LDEsMSxOLCJMQUtFIFZBTExFWSBTRUVEIgpBNjIsMTkyLDAsNCwxLDEsTiwiMzAzNDQ5NDg4MiIKQTYyLDIyMCwwLDQsMSwxLE4sIjU3MTcgQVJBUEFIT0UgU1RSRUVUIgpBNjIsMjUwLDAsMywyLDIsTiwiQk9VTERFUiAgQ08gODAzMDIiCkE0NDcsOSwwLDQsMSwyLE4sIjM1IExCUyAiCkE2NjgsMTMsMCw0LDEsMSxOLCIgMSBPRiAxIgpBNjM3LDY3MSwwLDQsMyw0LE4sIiAgICIKTE82NjEsNjQ5LDEyNCwxMjUKQjMwNCw1MjMsMCwxLDMsMywxMDcsTiwiNDIwODAzMDIiCkEyOTksNDM5LDAsNCwyLDMsTiwiQ08gODAzIDAtMDEiCkExMiw2NzIsMCwzLDIsMixOLCJVUFMgR1JPVU5EIgpBMTIsNzI5LDAsNCwxLDEsTiwiVFJBQ0tJTkcgIzogMVogOTUzIEU3OSAwMyA5MzUzIDYxODMiCkxPMCw3NzQsNzg1LDQKQTgxMSwxMDM4LDAsMywxLDEsTiwiICIKQTEyLDEwMzQsMCwzLDEsMSxOLCJCSUxMSU5HOiAiCkExMzksMTAzNCwwLDMsMSwxLE4sIlAvUCAiCkExNywxMzQsMCw0LDEsMSxOLCJTSElQIFRPOiAiCkxPMCw2NDcsNzg1LDE0CkxPMCwxMDEyLDc4NSwxNApMTzAsNDIzLDc4NSw0CkxPMjQzLDQyMyw0LDIyNApBMzgyLDExOTUsMCwxLDEsMSxOLCJYT0wgMDIuMDcuMTAgICAgICAgICAgTlY0NSA1NC4wQSAwNC8yMDA2IgpCMTA2LDc5MSwwLDEsMywzLDIwOCxOLCIxWjk1M0U3OTAzOTM1MzYxODMiCkEyODEsODc2LDAsNCwzLDQsTiwiU0FNUExFIgpHVzYyOSwxMTE2LDE5LDUyCgAAAAAAAAAAAAAAAAAAD/////8AAAAAAAAAAAAAAAAAAA//////AAAAAAAAAAAAAAAAAAAP/////wAAAAAAAAAAAAAAAAAAD/////8P////////D////////w//////D////////w////////8P/////w//////w/8P/D//////D/////8P/////8P/D/w//////w//////D/////8A/w/wD/////8P/////w//////AP8P8A//////D/////8P/////AAPDwAD/////w//////D/////wADw8AA/////8P/////w/////8DAMMAwP/////D/////8P/////AwDDAMD/////w//////D/////wPAAAPA/////8P/////w/////8DwAADwP/////D/////8P/////APAADwP/////w//////D/////wDwAA8D/////8P/////w//////AAAAAD//////D/////8P/////wAAAAA//////w//////AAAAAAAAAAAAAAAAAAAP/////wAAAAAAAAAAAAAAAAAAD/////8AAAAAAAAAAAAAAAAAAA//////AAAAAAAAAAAAAAAAAAAP/////w///////8AAP///////D/////8P///////AAD///////w//////D///////AAAP//////8P/////w///////wAAD///////D/////8P//////AAAAD//////w//////D//////wAAAA//////8P/////w//////AA8PAD//////D/////8P/////wAPDwA//////w//////D/////wA/w/AA/////8P/////w/////8AP8PwAP/////D/////8P/////AP/D/AD/////w//////D/////wD/w/wA/////8P/////w//////D/8P/w//////D8APP/wP/////w//D/8P/////w/ADz/8D////////w////////8P/P8//A////////8P////////D/z/P/wAAAAAAAAAAAAAAAAAAA/8/w/wAAAAAAAAAAAAAAAAAAAP/P8P8AAAAAAAAAAAAAAAAAAAD/z/D/AAAAAAAAAAAAAAAAAAAA/8/w/w/////////////////////P8zzP////////////////////z/M8z////////////////////8/zPM/////////////////////P8zzP////////////////////z/PDz////////////////////8/zw8/////////////////////P88PP////////////////////z/PDxQMQoK
 
 

Re:Base64 decode

"Rick" <XXXX@XXXXX.COM>writes
Quote
My problem is a bunch of extraneous "junk" I get back in the encoded tag.
Please be more specific. What does it actually look like?
Quote
When I decode using an idDecodeMIME component, the end of the data is
truncated about where all the "/////" start (near the end of the data).
'/' is a valid character in Base64 encoded data. There should not be able
truncation occuring during the decoding. What is the actual size of the
decoded data? What does it actually look like? Please post it to the
.attachments newsgroup, along with the original XML.
Quote
First I want to make sure the return value from a POST does not
go through any transformation that could cause some kind of
change to the data UPS is sending back.
That depends on how the server is sending the data back. TIdHTTP expects
ANSI-compatible data if you are accepting the data as a String. If the data
is not ANSI or UTF-8, then it could be changing the data when converted to
an ANSI String. Fortunately, UTF-8 is the default charset for XML, but it
does support other charsets as well.
Quote
XMLReply.XML.Add( idHTTP1.Post(
'https://wwwcie.ups.com/ups.app/xml/ShipConfirm', MS ));
where MS is a TMemoryStream containing the XML I am POSTing.
Have you tried accepting the response data as a TStream as well? That
would, at least, eliminate the possibility of the bytes being altered
unexpectedly.
idHTTP1.Post('https://wwwcie.ups.com/ups.app/xml/ShipConfirm', MS, MS2);
MS2.Position := 0;
XMLReply.XML.LoadFromStream(MS2);
Where MS and MS2 are both TMemoryStream.
Quote
there don't appear to be any decode options except the
FillChar in the idDecodeMIME, but am I missing something?
There are no other options available when decoding Base64. It is a very
straight-forward algorithm.
Quote
Raw Base64 data returned:
Please show it in the context of the original XML.
Gambit
 

Re:Base64 decode

On 2006-09-07, Rick (69.15.81.137) wrote in
message <45005abd$XXXX@XXXXX.COM>
Quote

And second, there don't appear to be any decode options except the FillChar
in the idDecodeMIME, but am I missing something? When I use Base64 decode
tools on the web, I get similar results.

Thanks for any pointers,

Rick


Raw Base64 data returned:
STgsQSwwMDEKSTgsQSwwMDEKT0QKcTc5NQpRMTYwMCwyNApTMgpEMTAKSkYKTgpiMTMsNDI5LE0sIjAwMyw4NDAsODAzMDIsMDAwMCxbKT4eMDEdOTYxWjkzNTM2MTgzHVVQU04dOTUzRTc5HjA3UCNcDSxXKklLJzMqKC1TQThDUi5NHTlNVSQqLlwiSDBDSjhMSVgvMzRMNlgjU1wNHgQiCkExNyw3LDAsMiwxLDEsTiwiU0VFRFMgQlkgREVTSUdOIElOQyIKQTE3LDI0LDAsMiwxLDEsTiwiNDM5OSBNQ0RFUk1PVFQgUk9BRCIKQTE3LDQxLDAsMiwxLDEsTiwiTUFYV0VMTCAgQ0EgOTU5NTUiCkE2MiwxNjQsMCw0LDEsMSxOLCJMQUtFIFZBTExFWSBTRUVEIgpBNjIsMTkyLDAsNCwxLDEsTiwiMzAzNDQ5NDg4MiIKQTYyLDIyMCwwLDQsMSwxLE4sIjU3MTcgQVJBUEFIT0UgU1RSRUVUIgpBNjIsMjUwLDAsMywyLDIsTiwiQk9VTERFUiAgQ08gODAzMDIiCkE0NDcsOSwwLDQsMSwyLE4sIjM1IExCUyAiCkE2NjgsMTMsMCw0LDEsMSxOLCIgMSBPRiAxIgpBNjM3LDY3MSwwLDQsMyw0LE4sIiAgICIKTE82NjEsNjQ5LDEyNCwxMjUKQjMwNCw1MjMsMCwxLDMsMywxMDcsTiwiNDIwODAzMDIiCkEyOTksNDM5LDAsNCwyLDMsTiwiQ08gODAzIDAtMDEiCkExMiw2NzIsMCwzLDIsMixOLCJVUFMgR1JPVU5EIgpBMTIsNzI5LDAsNCwxLDEsTiwiVFJBQ0tJTkcgIzogMVogOTUzIEU3OSAwMyA5MzUzIDYxODMiCkxPMCw3NzQsNzg1LDQKQTgxMSwxMDM4LDAsMywxLDEsTiwiICIKQTEyLDEwMzQsMCwzLDEsMSxOLCJCSUxMSU5HOiAiCkExMzksMTAzNCwwLDMsMSwxLE4sIlAvUCAiCkExNywxMzQsMCw0LDEsMSxOLCJTSElQIFRPOiAiCkxPMCw2NDcsNzg1LDE0CkxPMCwxMDEyLDc4NSwxNApMTzAsNDIzLDc4NSw0CkxPMjQzLDQyMyw0LDIyNApBMzgyLDExOTUsMCwxLDEsMSxOLCJYT0wgMDIuMDcuMTAgICAgICAgICAgTlY0NSA1NC4wQSAwNC8yMDA2IgpCMTA2LDc5MSwwLDEsMywzLDIwOCxOLCIxWjk1M0U3OTAzOTM1MzYxODMiCkEyODEsODc2LDAsNCwzLDQsTiwiU0FNUExFIgpHVzYyOSwxMTE2LDE5LDUyCgAAAAAAAAAAAAAAAAAAD/////8AAAAAAAAAAAAAAAAAAA//////AAAAAAAAAAAAAAAAAAAP/////wAAAAAAAAAAAAAAAAAAD/////8P////////D////////w//////D////////w////////8P/////w//////w/8P/D//////D/////8P/////8P/D/w//////w//////D/////8A/w/wD/////8P/////w//////AP8P8A//////D/////8P/////AAPDwAD/////w//////D/////wADw8AA/////8P/////w/////8DAMMAwP/////D/////8P/////AwDDAMD/////w//////D/////wPAAAPA/////8P/////w/////8DwAADwP/////D/////8P/////APAADwP/////w//////D/////wDwAA8D/////8P/////w//////AAAAAD//////D/////8P/////wAAAAA//////w//////AAAAAAAAAAAAAAAAAAAP/////wAAAAAAAAAAAAAAAAAAD/////8AAAAAAAAAAAAAAAAAAA//////AAAAAAAAAAAAAAAAAAAP/////w///////8AAP///////D/////8P///////AAD///////w//////D///////AAAP//////8P/////w///////wAAD///////D/////8P//////AAAAD//////w//////D//////wAAAA//////8P/////w//////AA8PAD//////D/////8P/////wAPDwA//////w//////D/////wA/w/AA/////8P/////w/////8AP8PwAP/////D/////8P/////AP/D/AD/////w//////D/////wD/w/wA/////8P/////w//////D/8P/w//////D8APP/wP/////w//D/8P/////w/ADz/8D////////w////////8P/P8//A////////8P////////D/z/P/wAAAAAAAAAAAAAAAAAAA/8/w/wAAAAAAAAAAAAAAAAAAAP/P8P8AAAAAAAAAAAAAAAAAAAD/z/D/AAAAAAAAAAAAAAAAAAAA/8/w/w/////////////////////P8zzP////////////////////z/M8z////////////////////8/zPM/////////////////////P8zzP////////////////////z/PDz////////////////////8/zw8/////////////////////P88PP////////////////////z/PDxQMQoK
In a previous life, I have written a base64 coder/decoder with Delphi.
When I cut & paste your data into it, it *seems* to return sensible
data:
-----------------------------------------
I8,A,001
I8,A,001
OD
q795
Q1600,24
S2
D10
JF
N
b13,429,M,"003,840,80302,0000,[)>01961Z93536183UPSN953E7907P#\
,W*IK'3*(-SA8CR.M9MU$*.\"H0CJ8LIX/34L6X#S\
"
A17,7,0,2,1,1,N,"SEEDS BY DESIGN INC"
A17,24,0,2,1,1,N,"4399 MCDERMOTT ROAD"
A17,41,0,2,1,1,N,"MAXWELL CA 95955"
A62,164,0,4,1,1,N,"LAKE VALLEY SEED"
A62,192,0,4,1,1,N,"3034494882"
A62,220,0,4,1,1,N,"5717 ARAPAHOE STREET"
A62,250,0,3,2,2,N,"BOULDER CO 80302"
A447,9,0,4,1,2,N,"35 LBS "
A668,13,0,4,1,1,N," 1 OF 1"
A637,671,0,4,3,4,N," "
LO661,649,124,125
B304,523,0,1,3,3,107,N,"42080302"
A299,439,0,4,2,3,N,"CO 803 0-01"
A12,672,0,3,2,2,N,"UPS GROUND"
A12,729,0,4,1,1,N,"TRACKING #: 1Z 953 E79 03 9353 6183"
LO0,774,785,4
A811,1038,0,3,1,1,N," "
A12,1034,0,3,1,1,N,"BILLING: "
A139,1034,0,3,1,1,N,"P/P "
A17,134,0,4,1,1,N,"SHIP TO: "
LO0,647,785,14
LO0,1012,785,14
LO0,423,785,4
LO243,423,4,224
A382,1195,0,1,1,1,N,"XOL 02.07.10 NV45 54.0A 04/2006"
B106,791,0,1,3,3,208,N,"1Z953E790393536183"
A281,876,0,4,3,4,N,"SAMPLE"
GW629,1116,19,52
-------------------------
If you need the code:
<users.pandora.be/dirk.claessens2/downloads/base64.zip>
HTH,
--
Dirk.
No trees were killed in the creation of this message;
however, many electrons were terribly inconvenienced.
users.pandora.be/dirk.claessens2
 

Re:Base64 decode

Thanks Remy and Dirk
Remy, I posted the returned raw stream at the bottom of the original post
plus the decoded information above that.
I will try the stream for the return information and see if that helps.
The data decodes to this:
<snip>
B106,791,0,1,3,3,208,N,"1Z953E790393536183"
A281,876,0,4,3,4,N,"SAMPLE"
GW629,1116,19,52 <binary data should be here, but everything is truncated
after this point>
<P1 should be here>
These are commands to a Zebra label printer and the "GW" indicates that a
graphic follows. In this case binary data follows and a final line with
"P1" which causes the label to print. In the decode, the binary data is
truncated and the "P1" is missing, like in Dirks decode. I can see the
binary data when I decode online at www.toastedspam.com/decode64
Anyway this whole senario with XML for UPS is a bit odd since they do many
non-standard things that make a programmers life more difficult.
Rick
"Rick" <XXXX@XXXXX.COM>writes
Quote
Indy 10.0.76
D7 Pro

I'm trying to integrate the XML online tools for UPS. Unlike Fedex, whose
online support was very prompt, UPS is quite slow and not very helpful.

The abbrieviated process is like this: Send an XML file via a HTTP POST
request using an idHTTP component. Then UPS sends back an XML file with a
<GraphicImage>tag that contains a Base64 encoded set of instructions to
send to a Zebra label printer.

My problem is a bunch of extraneous "junk" I get back in the encoded tag.
See below for the raw data. When I decode using an idDecodeMIME component,
the end of the data is truncated about where all the "/////" start (near
the end of the data).

First I want to make sure the return value from a POST does not go through
any transformation that could cause some kind of change to the data UPS is
sending back. My POST looks like this:
XMLReply.XML.Clear;
XMLReply.XML.Add( idHTTP1.Post(
'https://wwwcie.ups.com/ups.app/xml/ShipConfirm', MS ));
where MS is a TMemoryStream containing the XML I am POSTing.

And second, there don't appear to be any decode options except the
FillChar in the idDecodeMIME, but am I missing something? When I use
Base64 decode tools on the web, I get similar results.

Thanks for any pointers,

Rick


Raw Base64 data returned:
STgsQSwwMDEKSTgsQSwwMDEKT0QKcTc5NQpRMTYwMCwyNApTMgpEMTAKSkYKTgpiMTMsNDI5LE0sIjAwMyw4NDAsODAzMDIsMDAwMCxbKT4eMDEdOTYxWjkzNTM2MTgzHVVQU04dOTUzRTc5HjA3UCNcDSxXKklLJzMqKC1TQThDUi5NHTlNVSQqLlwiSDBDSjhMSVgvMzRMNlgjU1wNHgQiCkExNyw3LDAsMiwxLDEsTiwiU0VFRFMgQlkgREVTSUdOIElOQyIKQTE3LDI0LDAsMiwxLDEsTiwiNDM5OSBNQ0RFUk1PVFQgUk9BRCIKQTE3LDQxLDAsMiwxLDEsTiwiTUFYV0VMTCAgQ0EgOTU5NTUiCkE2MiwxNjQsMCw0LDEsMSxOLCJMQUtFIFZBTExFWSBTRUVEIgpBNjIsMTkyLDAsNCwxLDEsTiwiMzAzNDQ5NDg4MiIKQTYyLDIyMCwwLDQsMSwxLE4sIjU3MTcgQVJBUEFIT0UgU1RSRUVUIgpBNjIsMjUwLDAsMywyLDIsTiwiQk9VTERFUiAgQ08gODAzMDIiCkE0NDcsOSwwLDQsMSwyLE4sIjM1IExCUyAiCkE2NjgsMTMsMCw0LDEsMSxOLCIgMSBPRiAxIgpBNjM3LDY3MSwwLDQsMyw0LE4sIiAgICIKTE82NjEsNjQ5LDEyNCwxMjUKQjMwNCw1MjMsMCwxLDMsMywxMDcsTiwiNDIwODAzMDIiCkEyOTksNDM5LDAsNCwyLDMsTiwiQ08gODAzIDAtMDEiCkExMiw2NzIsMCwzLDIsMixOLCJVUFMgR1JPVU5EIgpBMTIsNzI5LDAsNCwxLDEsTiwiVFJBQ0tJTkcgIzogMVogOTUzIEU3OSAwMyA5MzUzIDYxODMiCkxPMCw3NzQsNzg1LDQKQTgxMSwxMDM4LDAsMywxLDEsTiwiICIKQTEyLDEwMzQsMCwzLDEsMSxOLCJCSUxMSU5HOiAiCkExMzksMTAzNCwwLDMsMSwxLE4sIlAvUCAiCkExNywxMzQsMCw0LDEsMSxOLCJTSElQIFRPOiAiCkxPMCw2NDcsNzg1LDE0CkxPMCwxMDEyLDc4NSwxNApMTzAsNDIzLDc4NSw0CkxPMjQzLDQyMyw0LDIyNApBMzgyLDExOTUsMCwxLDEsMSxOLCJYT0wgMDIuMDcuMTAgICAgICAgICAgTlY0NSA1NC4wQSAwNC8yMDA2IgpCMTA2LDc5MSwwLDEsMywzLDIwOCxOLCIxWjk1M0U3OTAzOTM1MzYxODMiCkEyODEsODc2LDAsNCwzLDQsTiwiU0FNUExFIgpHVzYyOSwxMTE2LDE5LDUyCgAAAAAAAAAAAAAAAAAAD/////8AAAAAAAAAAAAAAAAAAA//////AAAAAAAAAAAAAAAAAAAP/////wAAAAAAAAAAAAAAAAAAD/////8P////////D////////w//////D////////w////////8P/////w//////w/8P/D//////D/////8P/////8P/D/w//////w//////D/////8A/w/wD/////8P/////w//////AP8P8A//////D/////8P/////AAPDwAD/////w//////D/////wADw8AA/////8P/////w/////8DAMMAwP/////D/////8P/////AwDDAMD/////w//////D/////wPAAAPA/////8P/////w/////8DwAADwP/////D/////8P/////APAADwP/////w//////D/////wDwAA8D/////8P/////w//////AAAAAD//////D/////8P/////wAAAAA//////w//////AAAAAAAAAAAAAAAAAAAP/////wAAAAAAAAAAAAAAAAAAD/////8AAAAAAAAAAAAAAAAAAA//////AAAAAAAAAAAAAAAAAAAP/////w///////8AAP///////D/////8P///////AAD///////w//////D///////AAAP//////8P/////w///////wAAD///////D/////8P//////AAAAD//////w//////D//////wAAAA//////8P/////w//////AA8PAD//////D/////8P/////wAPDwA//////w//////D/////wA/w/AA/////8P/////w/////8AP8PwAP/////D/////8P/////AP/D/AD/////w//////D/////wD/w/wA/////8P/////w//////D/8P/w//////D8APP/wP/////w//D/8P/////w/ADz/8D////////w////////8P/P8//A////////8P////////D/z/P/wAAAAAAAAAAAAAAAAAAA/8/w/wAAAAAAAAAAAAAAAAAAAP/P8P8AAAAAAAAAAAAAAAAAAAD/z/D/AAAAAAAAAAAAAAAAAAAA/8/w/w/////////////////////P8zzP////////////////////z/M8z////////////////////8/zPM/////////////////////P8zzP////////////////////z/PDz////////////////////8/zw8/////////////////////P88PP////////////////////z/PDxQMQoK

 

Re:Base64 decode

"Rick" <XXXX@XXXXX.COM>writes
Quote
Remy, I posted the returned raw stream at the bottom of
the original post plus the decoded information above that.
No, you didn't. You showed just the Base64 data, and none of the XML.
Quote
The data decodes to this:
Please show the actual code you are using to decode the Base64 data. You
are probably trying to interpret the binary data as a null-terminated
string, so it truncates at the first $00 byte.
Quote
I can see the binary data when I decode online at
www.toastedspam.com/decode64
Then you are not decoding the data properly.
Quote
Anyway this whole senario with XML for UPS is a bit odd since
they do many non-standard things that make a programmers
life more difficult.
XML is becoming very popular nowadays. There are quite a few XML-based
protocols popping up.
Gambit
 

Re:Base64 decode

Remy,
I tried to POST to a memory stream like you suggested, but the results were
the same.
Here is the decoding part:
Node is an IXMLNode
SS is a TStringStream
Node := XMLReply.DocumentElement.ChildNodes.FindNode(
'ShipmentResults' ).ChildNodes.FindNode(
'PackageResults').ChildNodes.FindNode( 'LabelImage').ChildNodes.FindNode(
'GraphicImage');
SS.WriteString( idDecode.DecodeString( Node.NodeValue ) );
Here is the XML I get back:
The part to decode is in <GraphicImage>
<?xml version="1.0"?>
<ShipmentAcceptResponse><Response><TransactionReference><CustomerContext>Test
shipment</CustomerContext><XpciVersion>1.0001</XpciVersion></TransactionReference><ResponseStatusCode>1</ResponseStatusCode><ResponseStatusDescription>Success</ResponseStatusDescription></Response><ShipmentResults><ShipmentCharges><TransportationCharges><CurrencyCode>USD</CurrencyCode><MonetaryValue>44.23</MonetaryValue></TransportationCharges><ServiceOptionsCharges><CurrencyCode>USD</CurrencyCode><MonetaryValue>0.00</MonetaryValue></ServiceOptionsCharges><TotalCharges><CurrencyCode>USD</CurrencyCode><MonetaryValue>44.23</MonetaryValue></TotalCharges></ShipmentCharges><NegotiatedRates><NetSummaryCharges><GrandTotal><CurrencyCode>USD</CurrencyCode><MonetaryValue>43.79</MonetaryValue></GrandTotal></NetSummaryCharges></NegotiatedRates><BillingWeight><UnitOfMeasurement><Code>LBS</Code></UnitOfMeasurement><Weight>5.0</Weight></BillingWeight><ShipmentIdentificationNumber>1Z953E790191888417</ShipmentIdentificationNumber><PackageResults><TrackingNumber>1Z953E790191888417</TrackingNumber><ServiceOptionsCharges><CurrencyCode>USD</CurrencyCode><MonetaryValue>0.00</MonetaryValue></ServiceOptionsCharges><LabelImage><LabelImageFormat><Code>EPL</Code></LabelImageFormat><GraphicImage>STgsQSwwMDEKSTgsQSwwMDEKT0QKcTc5NQpRMTYwMCwyNApTMgpEMTAKSkYKTgpiMTMsNDI5LE0sIjAwMSw4NDAsODAzMDIsMDAwMCxbKT4eMDEdOTYxWjkxODg4NDE3HVVQU04dOTUzRTc5HjA3ICgxXA0kTVlSJzMqKC1TQThDUi5NHTlNVSQqLlwiSDBDSjhMSVgvMzRMNlgjU1wNHgQiCkExNyw3LDAsMiwxLDEsTiwiU0VFRFMgQlkgREVTSUdOIElOQyIKQTE3LDI0LDAsMiwxLDEsTiwiNDM5OSBNQ0RFUk1PVFQgUk9BRCIKQTE3LDQxLDAsMiwxLDEsTiwiTUFYV0VMTCAgQ0EgOTU5NTUiCkE2MiwxNjQsMCw0LDEsMSxOLCJMQUtFIFZBTExFWSBTRUVEIgpBNjIsMTkyLDAsNCwxLDEsTiwiMzAzNDQ5NDg4MiIKQTYyLDIyMCwwLDQsMSwxLE4sIjU3MTcgQVJBUEFIT0UgU1RSRUVUIgpBNjIsMjUwLDAsMywyLDIsTiwiQk9VTERFUiAgQ08gODAzMDIiCkE0NDcsOSwwLDQsMSwyLE4sIjUgTEJTICIKQTY2OCwxMywwLDQsMSwxLE4sIiAxIE9GIDEiCkE2MzcsNjcxLDAsNCwzLDQsTiwiMSAgIgpCMzA0LDUyMywwLDEsMywzLDEwNyxOLCI0MjA4MDMwMiIKQTI5OSw0MzksMCw0LDIsMyxOLCJDTyA4MDMgMC0wMSIKQTEyLDY3MiwwLDMsMiwyLE4sIlVQUyBORVhUIERBWSBBSVIiCkExMiw3MjksMCw0LDEsMSxOLCJUUkFDS0lORyAjOiAxWiA5NTMgRTc5IDAxIDkxODggODQxNyIKTE8wLDc3NCw3ODUsNApBODExLDEwMzgsMCwzLDEsMSxOLCIgIgpBMTIsMTAzNCwwLDMsMSwxLE4sIkJJTExJTkc6ICIKQTEzOSwxMDM0LDAsMywxLDEsTiwiUC9QICIKQTE3LDEzNCwwLDQsMSwxLE4sIlNISVAgVE86ICIKTE8wLDY0Nyw3ODUsMTQKTE8wLDEwMTIsNzg1LDE0CkxPMCw0MjMsNzg1LDQKTE8yNDMsNDIzLDQsMjI0CkEzODIsMTE5NSwwLDEsMSwxLE4sIlhPTCAwMi4wNy4xMCAgICAgICAgICBOVjQ1IDU0LjBBIDA0LzIwMDYiCkIxMDYsNzkxLDAsMSwzLDMsMjA4LE4sIjFaOTUzRTc5MDE5MTg4ODQxNyIKQTI4MSw4NzYsMCw0LDMsNCxOLCJTQU1QTEUiCkdXNjI5LDExMTYsMTksNTIKAAAAAAAAAAAAAAAAAAAP/////wAAAAAAAAAAAAAAAAAAD/////8AAAAAAAAAAAAAAAAAAA//////AAAAAAAAAAAAAAAAAAAP/////w////////8P////////D/////8P////////D////////w//////D//////D/w/8P/////8P/////w//////w/8P/D//////D/////8P/////wD/D/AP/////w//////D/////8A/w/wD/////8P/////w/////8AA8PAAP/////D/////8P/////AAPDwAD/////w//////D/////wMAwwDA/////8P/////w/////8DAMMAwP/////D/////8P/////A8AAA8D/////w//////D/////wPAAAPA/////8P/////w/////8A8AAPA//////D/////8P/////APAADwP/////w//////D/////8AAAAAP/////8P/////w//////AAAAAD//////D/////8AAAAAAAAAAAAAAAAAAA//////AAAAAAAAAAAAAAAAAAAP/////wAAAAAAAAAAAAAAAAAAD/////8AAAAAAAAAAAAAAAAAAA//////D///////wAA///////8P/////w///////8AAP///////D/////8P//////8AAA///////w//////D///////AAAP//////8P/////w//////8AAAAP//////D/////8P//////AAAAD//////w//////D/////8ADw8AP/////8P/////w//////AA8PAD//////D/////8P/////AD/D8AD/////w//////D/////wA/w/AA/////8P/////w/////8A/8P8AP/////D/////8P/////AP/D/AD/////w//////D/////8P/w//D/////8PwA8//A//////D/8P/w//////D8APP/wP////////D////////w/8/z/8D////////w////////8P/P8//AAAAAAAAAAAAAAAAAAAD/z/D/AAAAAAAAAAAAAAAAAAAA/8/w/wAAAAAAAAAAAAAAAAAAAP/P8P8AAAAAAAAAAAAAAAAAAAD/z/D/D////////////////////8/zPM/////////////////////P8zzP////////////////////z/M8z////////////////////8/zPM/////////////////////P88PP////////////////////z/PDz////////////////////8/zw8/////////////////////P88PFAxCgo=</GraphicImage></LabelImage></PackageResults></ShipmentResults></ShipmentAcceptResponse>
"Remy Lebeau (TeamB)" <XXXX@XXXXX.COM>writes
Quote

"Rick" <XXXX@XXXXX.COM>writes
news:XXXX@XXXXX.COM...

>Remy, I posted the returned raw stream at the bottom of
>the original post plus the decoded information above that.

No, you didn't. You showed just the Base64 data, and none of the XML.

>The data decodes to this:

Please show the actual code you are using to decode the Base64 data. You
are probably trying to interpret the binary data as a null-terminated
string, so it truncates at the first $00 byte.

>I can see the binary data when I decode online at
>www.toastedspam.com/decode64

Then you are not decoding the data properly.

>Anyway this whole senario with XML for UPS is a bit odd since
>they do many non-standard things that make a programmers
>life more difficult.

XML is becoming very popular nowadays. There are quite a few XML-based
protocols popping up.


Gambit


 

Re:Base64 decode

"Rick" <XXXX@XXXXX.COM>writes
Quote
SS.WriteString( idDecode.DecodeString( Node.NodeValue ) );
DecodeString() returns the decoded data as a String. You are decoding
binary data instead, so you should not be using DecodeString(). You should
also not be storing the decoded binary data into a string-based stream,
either.
You are also using an old version of Indy 10. Update to the latest Indy
10.1.5 snapshot, and then try the following:
var
Node: IXMLNode;
SS: TIdStringStream;
MS: TIdMemoryStream;
Decoder: TIdDecoderMIME;
begin
// you might want to consider using XPath for this instead...
Node :=
XMLReply.DocumentElement.ChildNodes['ShipmentResults'].ChildNodes['PackageRe
sults'].ChildNodes['LabelImage'].ChildNodes['GraphicImage'];
SS := TIdStringString.Create(Node.NodeValue);
try
MS := TIdMemoryStream.Create;
try
Decoder := TIdDecoderMIME.Create;
try
Decoder.DecodeBegin(MS);
try
Decoder.Decode(SS);
finally
Decoder.DecodeEnd;
end;
finally
Sys.FreeAndNil(IdDecoder);
end;
finally
Sys.FreeAndNil(MS);
end;
finally
Sys.FreeAndNil(SS);
end;
end;
Gambit
 

Re:Base64 decode

"Remy Lebeau (TeamB)" <XXXX@XXXXX.COM>writes
Quote

"Rick" <XXXX@XXXXX.COM>writes
news:450087a6$XXXX@XXXXX.COM...

>SS.WriteString( idDecode.DecodeString( Node.NodeValue ) );

DecodeString() returns the decoded data as a String. You are decoding
binary data instead, so you should not be using DecodeString(). You
should
also not be storing the decoded binary data into a string-based stream,
either.
Believe me, its not my choice to store binary and string data in the same
tag. This is partly why I find UPS's system so difficult to deal with.
I use XPath from within XSLT stylesheets. Are you suggesting I can use it
also from an IXMLDocument? That would certainly be easier, but how?
I'll give this suggestion a try.
Rick
Quote

You are also using an old version of Indy 10. Update to the latest Indy
10.1.5 snapshot, and then try the following:

var
Node: IXMLNode;
SS: TIdStringStream;
MS: TIdMemoryStream;
Decoder: TIdDecoderMIME;
begin
// you might want to consider using XPath for this instead...
Node :=
XMLReply.DocumentElement.ChildNodes['ShipmentResults'].ChildNodes['PackageRe
sults'].ChildNodes['LabelImage'].ChildNodes['GraphicImage'];

SS := TIdStringString.Create(Node.NodeValue);
try
MS := TIdMemoryStream.Create;
try
Decoder := TIdDecoderMIME.Create;
try
Decoder.DecodeBegin(MS);
try
Decoder.Decode(SS);
finally
Decoder.DecodeEnd;
end;
finally
Sys.FreeAndNil(IdDecoder);
end;
finally
Sys.FreeAndNil(MS);
end;
finally
Sys.FreeAndNil(SS);
end;
end;


Gambit


 

Re:Base64 decode

I upgraded to 10.1.5, figured out why my SSL would not work anymore,
upgraded the dll's for SSL.
The code you suggested did not return any different results. Thanks anyway
for the effort.
I think I will just have to parse and eliminate the line with the binary
information (graphic). It is only a little box logo that UPS puts at the
bottom of the label so it is not essential.
Rick
"Remy Lebeau (TeamB)" <XXXX@XXXXX.COM>writes
Quote

"Rick" <XXXX@XXXXX.COM>writes
news:450087a6$XXXX@XXXXX.COM...

>SS.WriteString( idDecode.DecodeString( Node.NodeValue ) );

DecodeString() returns the decoded data as a String. You are decoding
binary data instead, so you should not be using DecodeString(). You
should
also not be storing the decoded binary data into a string-based stream,
either.

You are also using an old version of Indy 10. Update to the latest Indy
10.1.5 snapshot, and then try the following:

var
Node: IXMLNode;
SS: TIdStringStream;
MS: TIdMemoryStream;
Decoder: TIdDecoderMIME;
begin
// you might want to consider using XPath for this instead...
Node :=
XMLReply.DocumentElement.ChildNodes['ShipmentResults'].ChildNodes['PackageRe
sults'].ChildNodes['LabelImage'].ChildNodes['GraphicImage'];

SS := TIdStringString.Create(Node.NodeValue);
try
MS := TIdMemoryStream.Create;
try
Decoder := TIdDecoderMIME.Create;
try
Decoder.DecodeBegin(MS);
try
Decoder.Decode(SS);
finally
Decoder.DecodeEnd;
end;
finally
Sys.FreeAndNil(IdDecoder);
end;
finally
Sys.FreeAndNil(MS);
end;
finally
Sys.FreeAndNil(SS);
end;
end;


Gambit


 

Re:Base64 decode

"Rick" <XXXX@XXXXX.COM>writes
Quote
I use XPath from within XSLT stylesheets. Are you suggesting I can
use it also from an IXMLDocument? That would certainly be easier,
but how?
Yes, but only if you are using the MSXML parser engine. You can query the
IXMLNode.DOMNode property for the IXMLDOMNode interface, and then call its
selectSingleNode() and selectNodes() methods to execute XPath expressions as
desired.
Gambit