javascript - Httpclient getResponseBodyAsString() returns not readable data -
i using httpclient in javascript file url , response body string store in database. code works fine in case of text but, other files extensions excel or png returns unreadable below.
the response is:
pk!ëx%e[content_types].xml ¢( ´ioÃ0ïhüÈw¸p@5åÀrjqvij/ò¸Û¿gÜ%j«¶)p.ç½÷ytfºn&àqy³ë¬Ã0ÒÊt9û¼¤w,Á l!jk gs@öл¼èæ0!µÁbp÷£yvjëµtë+îüðnçkkèÁzÝ'(ŸÉó/i©xò¸|/fålé¨Ïù^w$¹ziho|b®tÅrñÃ+?w¶6vº7*¦w$}áëÐdΧּ°r¬i×Ùq=¶,fÝ·ét5+z(³æ?ÈaÆzçi¬[!0ÌkÀó,}oÿtaô\ ém?i¬|¶Øж§atïsb¶;'m;y\9·"laøþoæ %µô@k8¡â?,fcÝ (small part of full log)
for image file:
.ß0ÊÍÍq#0¶0¡ø")%p4ÓêÂ,j«üÙö sògÖ59¥³÷eÞ3?»þ{0£e(Ú¢eäbûëttʽ6iend®b` (small part of full log)
for text response is:
this test file.
my code below :-
var httpclient = packages.org.apache.commons.httpclient; var httpclient = httpclient.httpclient; var getmethod = httpclient.methods.getmethod; var client = new httpclient(); var = new getmethod(url); var status = client.executemethod(get); gs.log("getting url: " + url); gs.log("--------------request headers------------------"); var reqheaders = get.getrequestheaders(); ( var = 0; < reqheaders.length; i++) { gs.log(reqheaders[i].getname() + " (req):" + reqheaders[i].getvalue()); } gs.log("--------------response headers------------------"); var headers = get.getresponseheaders(); ( = 0; < headers.length; i++) { gs.log(headers[i].getname() + " (resp) :" + headers[i].getvalue()); } var = get.getresponsebodyasstring(); gs.log("the response is"+is);
note : getresponsebodyasstream(); not option.
Comments
Post a Comment