Steve,
Unfortunately, it seems that you can’t get there from here. Basically, because XML is a character based format, as opposed to a binary format, it can’t handle binary data without some sort of encoding. BASE64 is the solution to the problem, but Witango doesn’t encode binary data (either automatically or explicitly). It looks like this is a feature I’ll have to add. So, as for your solution right now, the only thing you can do is execute 2 @URLS, one with the detailedresponse=true for the header and one without to get the raw binary data. I checked out the implementation in Witango 6 and the WebCall action and it doesn’t provide a single request solution either. Sorry I didn’t think this out further for you in a previous post. I’m not sure if you’ll be able to use this, but 2 requests does get you what you need. Robert From: Fogelson, Steve [mailto:[email protected]] Sent: Tuesday, March 08, 2011 8:50 PM To: [email protected] Subject: RE: Witango-Talk: Code Suggestions Hi Robert, Thanks for the information and especially the last two lines of code. I am pretty green on xpointer and xpath. I used the following to capture the BODY contents, but it only yields the first seven characters. <@assign request$Body "<@elementvalue object='request$URLContents' xpath='/HTTP_RESPONSE/BODY'>"> Body: <@var request$Body encoding="none"><br /> Body: GIF89ax Should be the following GIF89axL÷!!%!##)#1)!))!1)+)#/3‑%)1)5115)155;5‑<6&691??)6?63<BB<3ü°Æ‑°ÌQÊy_dÚ‰‹uŒ‚M3Î,—M9êÔö×:‹øÐ&°*þ У _____ #ð0‚8Ѝ[1]†‑ê€[1] L`°Þà 7€‘† 1DE,rÔ!Éy¼’ Äøb- 4“M:{ãÎ&Œ@A _____ 6 Etc, etc Appreciate some help. Thanks Steve _____ From: Robert Shubert [mailto:[email protected]] Sent: Sunday, March 06, 2011 11:52 PM To: [email protected] Subject: RE: Witango-Talk: Code Suggestions I put together the following to parse the xml. I was thinking that by checking the Status Code and making sure it was 200 that that would indicate the download was successful. Am I correct in assuming this? It’s a pretty good bet. All HTTP servers should respond a 200 message when returning the requested data, and some other code when not. For the most part, this works as you would expect. Mind you that some “friendly errors” may return as “200 OK”, even though you’re getting something like “Site is down for maintenance” or “server too busy to respond”. In the event I am not provided with the complete file name, I want to check the “Content-Type” so I can put the proper extension on the file when I save it. Is there a better way to accomplish this than the code I put together below? In a way, this question doesn’t make sense because you’re requesting the file and should, therefore, know it’s name. But I think you are dealing with data which is fed from a script, possibly fed from a database, so in these cases, yes you would need to analyze the Content-Type: header to determine the data type and then append the proper extension to the filename as you have done below. This is the only option available to you and will work. Said another way, if the server sends an incorrect Content-Type, a web browser would not be able to display the image properly, therefore you should be able to depend on it. That said, as a last ditch effort, you might be able to introspect the file to get its type. More times than not, the first few bytes of a file indicate it’s type. I wouldn’t try coding this until you find that you need it. The only minor comment I would make about your code is that there’s probably a little faster way to get the data you need from the DOM: Returns the Result Code: <@ELEMENTVALUE object=URLContents xpath="/HTTP_RESPONSE/STATUS/CODE"> Returns the Content-Type: <@ELEMENTVALUE object=URLContents xpath="/HTTP_RESPONSE/HEADER[@NAME='Content-Type']"> Robert Thanks Steve Fogelson Internet Commerce Solutions <@assign request$Status '<@elementname object="request$URLContents" xpath="/HTTP_RESPONSE/STATUS/*">'> <@assign request$StatusValues '<@elementvalue object="request$URLContents" xpointer="root().child(1).child(all)">'> <@for start="1" stop="<@numrows array='request$Status'>"> <@if "<@var request$Status[<@currow>,1]> = 'CODE'"> <@assign request$CODE "<@var request$StatusValues[<@currow>,1]>"> <@break> </@if> </@for> <@assign request$Names '<@elementattribute object="request$URLContents" attribute="NAME" xpath="/HTTP_RESPONSE/*">'> <@assign request$NameValues '<@elementvalue object="request$URLContents" xpointer="root().child(all)">'> <@for start="1" stop="<@numrows array='request$Names'>"> <@if "<@var request$Names[<@currow>,1]> = 'Content-Type'"> <@assign request$Content-TypeRow "<@currow>"> <@break> </@if> </@for> <@if "<@var request$Content-TypeRow> > 0"> <@if "<@var request$NameValues[<@calc '<@var request$Content-TypeRow> + 1'>,1]> = 'image/gif'"> <@assign request$FileType "gif"> <@elseif "<@var request$NameValues[<@calc '<@var request$Content-TypeRow> + 1'>,1]> = 'image/jpeg'"> <@assign request$FileType "jpg"> <@elseif "<@var request$NameValues[<@calc '<@var request$Content-TypeRow> + 1'>,1]> = 'image/jpg'"> <@assign request$FileType "jpg"> <@elseif "<@var request$NameValues[<@calc '<@var request$Content-TypeRow> + 1'>,1]> = 'image/png'"> <@assign request$FileType "png"> </@if> </@if> _____ To unsubscribe from this list, please send an email to [email protected] with "unsubscribe witango-talk" in the body. _____ To unsubscribe from this list, please send an email to [email protected] with "unsubscribe witango-talk" in the body. _____ To unsubscribe from this list, please send an email to [email protected] with "unsubscribe witango-talk" in the body. ---------------------------------------- To unsubscribe from this list, please send an email to [email protected] with "unsubscribe witango-talk" in the body.
