如何修复使用 MS2XML.XMLHTTP 请求的 PDF 文件中的损坏?
How can I fix the damage in PDF files requested using MS2XML.XMLHTTP?
朋友们,这是我的第一个问题...我在使用 MS2XML.XMLHTTP 下载 PDF 缓冲区时遇到了一些问题。我一直在使用 Genexus 这样做,但我也在纯 Visual Fox Pro 中尝试过。问题是,当我将 ResponseText 发送到字符串变量时,一些字符被问号替换,当我将 ResponseText 发送到 pdf 或 txt 文件时,就会发生这种情况。在 MS2XML.XMLHTTP.6.0 中创建的对象不允许使用 ResponseBody 属性。关于如何使用 MS2XML.XMLHTTP 解决它的任何想法?谢谢。
oHTTP = CreateObject("MSXML2.XMLHTTP.6.0")
oHTTP.Open("GET", 'https://homologacao.plugboleto.com.br/api/v1/boletos/impressa /lote/NIKLfYBWz',.F.)
oHTTP.setRequestHeader("content-type", "application/pdf")
oHTTP.Send()
? oHTTP.responseText
我收到了如下内容(全是问号):
%PDF-1.4 %??2 0 obj <>流 ???JFIF H H ??C !"$ “$??C?? &?" ?? ??? } !1AQa"q2???#B??R?$3br? %&'()456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz??????????????????????????? ??????????? ??? w !1AQaq"2?B????#3R??$4?&'()56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz??????????????????????? ????????????????????????????????????????????????????????? =24=]p1???|b?o????x?_???%??E?en9??T???T>.????JG??rx????? ????h?w???????:?!????????jlm?Tn??????u????? ?PA?? (?? (?? (?? (??>B???;.??3?e??J??~?F??? m=kw?????[?K#????vR@G??^$?????k?[??BSu??#???M??????_? ?Z?Fo???????/??*x?¾ mn??{)???80??s]W?x? ??+??k??=??????? ?8 ?|D?c?j???h???$?8???:c??(???M/?Ze??;O?[?J?????'?~ /j~!???n?urm???1^ITl;?3?%[?b??~?&<=u?Y\x??W6?¬$2?q?1?;??qc??_??qk>?&?v?????,??F?{??x???s??????{?k????r8.?
?????????!??9Va??c???Zv??x+?b?wd??f?8a????????, 6????????x???-????<9F????????[~$?{??o???X??????y?ZgQ?@ 8??ox;? ???|??mZ?? I~a?k ~P ??j???'?c??4?F??l??$?8???(?' "?.??????,????9V??????d????????UU)??? ???o?&????4?7?Z??g ???
W[?????d?Q$?@??^mZ???B Z(??QE ?Q@Q@Q@Q@Q@??endstream endobj 6 0 obj <>流x??V???+?q??z???'U./h???{???d?U??xf??PQ?O???unA??
?x1?0 50]@?\?T?y?B?s?9B? ? 2|????C???2t????k?U??]??]{? ?????s?AH??????h?"w????? f?????i??? ??>?9?8?#??"??G?$???<??0???S?2??sn?n??^?5?\FN?o1?4?~4~??Qe=&?T[???????Z??x??????k?????0z'#?;?'a?
?a?f~?q?~8ZH~?m????????mm?p?@hh{?????W7?????? ?
?8?Olk'?A|?[???P?5??????uGxRr#?pw<$y?n??kD ???0??ih??9?5v ??0?_}iG?Dq?8??_U??5a??????k????d???M??2???C(??;t2uA] z ??6A??o?t?}d????[?<;??R?iO8n??f???40???S?aVX? ???Y?p2N?eq]N?VeE?>??/V0?]MV?&???.aZ-???z2????????????8o??3?S ????????gf??B?'6??]?J endstream endobj 8 0 obj<>/XObject<>>>/Parent 7 0 R/MediaBox[0 0 595 842]>>endobj 3 0 obj<>endobj 4 0 obj<>endobj 5 0 obj <>/BBox[0 0 292.41 39]/Length 474>>stream x?m? ?e1C?@???1Ly}??Ua??>????r?R?????r?7gr??a???\??PTj??p???s????~m"???:K??T???1????Gw({c???? !???p?rB g M?QG*?PC ?o??v?????'n[!n2??}*?g}r?G??J?R"aI?S??q ???d;??-??m?????y?lCp??[B(=?L??G
[]2??)???
?8???9L????]y)?B??t?E??????I?????????@1?]$? ??h??6?Q[A)?8?????????z??8c??????s??R????%6 ? endstream endobj 1 0 obj <> /Length 1818/BBox[0 0 595.28 419.53]>>流 x???Ko???t??V|???4-$n??{Pm%]6????P???? :?$E?6i ?4??????d??m.U?7L????E???"???e?^r??c?????????S#'??????????X?bz?k.J?3!?)??{?V ??'VS1????? 8??L????fU"&Fx?v?Q?9G??EL]?iLIN}?C?i~??4???J?P?4Ec??F??P%c =!
?=?!U??P?T?b]???k>+¹&?5?9A5ai?"???G????H???J??J?#N??@?3dP ??#O=A6%??&dO?eU&5;?Q?@M?'??.??8????P???z!
'??j??O?8??7?
?f????????u???^???:N#?q?Y?xN6Kjv B??Z?????? Dx^?J??;A1?3s /?S?k?8??'?9?n??.w?s????g????? M<0????????<?,p???xG!pv?v?
?O??,?!pv?v?P?
?l?O??3 ?M)[??????????x??D?h????Z??&i)??,????k???k????j*???-? @?'?x9D)]?J:?=?G??1r? ???!???X?I???|n?q}?=?6?:
ðl??????_T??[??_?AC???YI??????+??]??}S?P<{??EY?? @??q?pah???,Pj?????v~??a?c???{R?7????? ?E~?mv??v?6??t ?? ??Y??????&???F?7P'?e??????R&??(?#??????????)?2???P??j?.I ??s4?|????s???$z????????E?P??x?{??tU?????????|??b?'?jH ????f6 .?g? “??????iVR”;;?P?'????F?????*??^?b?Nu6rO6? ?Xn[~>t???x2????n?[?D^???6C4O??vx??p?#???$?ru??Yj??55,?Z?? ?u?&?yy????%????+???aMk?3 ???v?1M\A&?q???? '?Sf?,??ce)? ??x??????P?#?Ea&y????/n??~8j????????Co??????????????%?? ????????5C???(??}???OA???a$?)J?`?!vd?????T????D{,?}^ ?e?]]@?'#T?v??J??;??4?G?e???&b?Bl???K?????.?t=s?i?;6. > ??????:?H??Z}:.V? ??) endstream endobj 9 0 obj<>endobj 10 0 obj<>endobj 11 0 obj<>endobj 12 0 obj<>endobj 13 0 obj<>endobj 14 0 obj<>endobj 7 0 obj<>endobj 15 0 obj< > endobj 16 0 obj << >> endobj xref 0 17 00000000000000000000000000000000000000004765 00000 n 000000000015 00000 N 00000000000000003908 00000 N 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000来0000006794 00000 N 00006833333300000 n 0000006863 00000 N 0000006922 00000 N 0000006965 00000 N 00000070444444444440000000000000000000000007240 00000 00000 N 0000000000 00000 N TRABLER TRABLER <61 16 16 1 16 1 16 1 16 1 17 = 61 =] = 61 =]起始外部参照 7305 %%EOF
由于 PDF 是二进制文件而不是文本文件,您会看到它很正常吗?以及各种其他不可打印的字符。而是将其保存到磁盘上的文件中,然后使用 ShellExecute 之类的工具打开。即:
oHTTP = CreateObject("MSXML2.XMLHTTP.6.0")
oHTTP.Open("GET", 'https://homologacao.plugboleto.com.br/api/v1/boletos/impressa /lote/NIKLfYBWz',.F.)
oHTTP.setRequestHeader("content-type", "application/pdf")
oHTTP.Send()
Local lcFileName
lcFileName = Forcepath(Sys(2015)+'.pdf', Sys(2023))
Strtofile(oHttp.responseText, m.lcFileName)
Declare Long ShellExecute In "shell32.dll" ;
long HWnd, String lpszOp, ;
string lpszFile, String lpszParams, ;
string lpszDir, Long nShowCmd
ShellExecute(_vfp.HWnd,'',m.lcFileName,'','',1)
编辑:这不是一份工作MSXML2.XmlHttp。您只需下载 PDF 文件并打开它:
Local lcFileName, lcRemote
lcRemote = 'https://homologacao.plugboleto.com.br/api/v1/boletos/impressao/lote/NIKLfYBWz'
lcFileName = Forcepath(Sys(2015)+'.pdf', Sys(2023))
If (getFileFromURL(m.lcRemote, m.lcFileName) = 0)
Declare Long ShellExecute In "shell32.dll" ;
long HWnd, String lpszOp, ;
string lpszFile, String lpszParams, ;
string lpszDir, Long nShowCmd
ShellExecute(_vfp.HWnd,'',m.lcFileName,'','',1)
Endif
Procedure getFileFromURL
Lparameters tcRemoteFile,tcLocalFile
Declare Integer URLDownloadToFile In urlmon.Dll;
INTEGER pCaller, String szURL, String szFileName,;
INTEGER dwReserved, Integer lpfnCB
Return URLDownloadToFile(0, m.tcRemoteFile, m.tcLocalFile, 0, 0)
endproc
朋友们,这是我的第一个问题...我在使用 MS2XML.XMLHTTP 下载 PDF 缓冲区时遇到了一些问题。我一直在使用 Genexus 这样做,但我也在纯 Visual Fox Pro 中尝试过。问题是,当我将 ResponseText 发送到字符串变量时,一些字符被问号替换,当我将 ResponseText 发送到 pdf 或 txt 文件时,就会发生这种情况。在 MS2XML.XMLHTTP.6.0 中创建的对象不允许使用 ResponseBody 属性。关于如何使用 MS2XML.XMLHTTP 解决它的任何想法?谢谢。
oHTTP = CreateObject("MSXML2.XMLHTTP.6.0")
oHTTP.Open("GET", 'https://homologacao.plugboleto.com.br/api/v1/boletos/impressa /lote/NIKLfYBWz',.F.)
oHTTP.setRequestHeader("content-type", "application/pdf")
oHTTP.Send()
? oHTTP.responseText
我收到了如下内容(全是问号):
%PDF-1.4 %??2 0 obj <>流 ???JFIF H H ??C !"$ “$??C?? &?" ?? ??? } !1AQa"q2???#B??R?$3br? %&'()456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz??????????????????????????? ??????????? ??? w !1AQaq"2?B????#3R??$4?&'()56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz??????????????????????? ????????????????????????????????????????????????????????? =24=]p1???|b?o????x?_???%??E?en9??T???T>.????JG??rx????? ????h?w???????:?!????????jlm?Tn??????u????? ?PA?? (?? (?? (?? (??>B???;.??3?e??J??~?F??? m=kw?????[?K#????vR@G??^$?????k?[??BSu??#???M??????_? ?Z?Fo???????/??*x?¾ mn??{)???80??s]W?x? ??+??k??=??????? ?8 ?|D?c?j???h???$?8???:c??(???M/?Ze??;O?[?J?????'?~ /j~!???n?urm???1^ITl;?3?%[?b??~?&<=u?Y\x??W6?¬$2?q? ????????!??9Va??c???Zv??x+?b?wd??f?8a????????, 6????????x???-????<9F????????[~$?{??o???X??????y?ZgQ?@ 8??ox;? ???|??mZ?? I~a?k ~P ??j???'?c??4?F??l??$?8???(?' "?.??????,????9V??????d????????UU)??? ???o?&????4?7?Z??g ???
W[?????d?Q$?@??^mZ???B Z(??QE ?Q@Q@Q@Q@Q@??endstream endobj 6 0 obj <>流x??V???+?q??z???'U./h???{???d?U??xf??PQ?O???unA??1?;??qc??_??qk>?&?v?????,??F?{??x???s??????{?k????r8.?
? 50]@?\?T?y?B?s?9B? ? 2|????C???2t????k?U??]??]{? ?????s?AH??????h?"w????? f?????i??? ??>?9?8?#??"??G?$???<??0???S?2??sn?n??^?5?\FN?o1?4?~4~??Qe=&?T[???????Z??x??????k?????0z'#?;?'a?
?a?f~?q?~8ZH~?m????????mm?p?@hh{?????W7?????? ?
?8?Olk'?A|?[???P?5??????uGxRr#?pw<$y?n??kD ???0??ih??9?5v ??0?_}iG?Dq?8??_U??5a??????k????d???M??2???C(??;t2uA] z ??6A??o?t?}d????[?<;??R?iO8n??f???40???S?aVX? ???Y?p2N?eq]N?VeE?>??/V0?]MV?&???.aZ-???z2????????????8o??3?S ????????gf??B?'6??]?J endstream endobj 8 0 obj<>/XObject<>>>/Parent 7 0 R/MediaBox[0 0 595 842]>>endobj 3 0 obj<>endobj 4 0 obj<>endobj 5 0 obj <>/BBox[0 0 292.41 39]/Length 474>>stream x?m? ?e1C?@???1Ly}??Ua??>????r?R?????r?7gr??a???\??PTj??p???s????~m"???:K??T???1????Gw({c???? !???p?rB g M?QG*?PC ?o??v?????'n[!n2??}*?g}r?G??J?R"aI?S??q ???d;??-??m?????y?lCp??[B(=?L??G
[]2??)???
?8???9L????]y)?B??t?E??????I?????????@1?]$? ??h??6?Q[A)?8?????????z??8c??????s??R????%6 ? endstream endobj 1 0 obj <> /Length 1818/BBox[0 0 595.28 419.53]>>流 x???Ko???t??V|???4-$n??{Pm%]6????P???? :?$E?6i ?4??????d??m.U?7L????E???"???e?^r??c?????????S#'??????????X?bz?k.J?3!?)??{?V ??'VS1????? 8??L????fU"&Fx?v?Q?9G??EL]?iLIN}?C?i~??4???J?P?4Ec??F??P%c =!
?=?!U??P?T?b]???k>+¹&?5?9A5ai?"???G????H???J??J?#N??@?3dP ??#O=A6%??&dO?eU&5;?Q?@M?'??.??8????P???z!
'??j??O?8??7?
?f????????u???^???:N#?q?Y?xN6Kjv B??Z?????? Dx^?J??;A1?3s /?S?k?8??'?9?n??.w?s????g????? M<0????????<?,p???xG!pv?v?
?O??,?!pv?v?P?
?l?O??3 ?M)[??????????x??D?h????Z??&i)??,????k???k????j*???-? @?'?x9D)]?J:?=?G??1r? ???!???X?I???|n?q}?=?6?:
ðl??????_T??[??_?AC???YI??????+??]??}S?P<{??EY?? @??q?pah???,Pj?????v~??a?c???{R?7????? ?E~?mv??v?6??t ?? ??Y??????&???F?7P'?e??????R&??(?#??????????)?2???P??j?.I ??s4?|????s???$z????????E?P??x?{??tU?????????|??b?'?jH ????f6 .?g? “??????iVR”;;?P?'????F?????*??^?b?Nu6rO6? ?Xn[~>t???x2????n?[?D^???6C4O??vx??p?#???$?ru??Yj??55,?Z?? ?u?&?yy????%????+???aMk?3 ???v?1M\A&?q???? '?Sf?,??ce)? ??x??????P?#?Ea&y????/n??~8j????????Co??????????????%?? ????????5C???(??}???OA???a$?)J?`?!vd?????T????D{,?}^ ?e?]]@?'#T?v??J??;??4?G?e???&b?Bl???K?????.?t=s?i?;6. > ??????:?H??Z}:.V? ??) endstream endobj 9 0 obj<>endobj 10 0 obj<>endobj 11 0 obj<>endobj 12 0 obj<>endobj 13 0 obj<>endobj 14 0 obj<>endobj 7 0 obj<>endobj 15 0 obj< > endobj 16 0 obj << >> endobj xref 0 17 00000000000000000000000000000000000000004765 00000 n 000000000015 00000 N 00000000000000003908 00000 N 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000来0000006794 00000 N 00006833333300000 n 0000006863 00000 N 0000006922 00000 N 0000006965 00000 N 00000070444444444440000000000000000000000007240 00000 00000 N 0000000000 00000 N TRABLER TRABLER <61 16 16 1 16 1 16 1 16 1 17 = 61 =] = 61 =]起始外部参照 7305 %%EOF
由于 PDF 是二进制文件而不是文本文件,您会看到它很正常吗?以及各种其他不可打印的字符。而是将其保存到磁盘上的文件中,然后使用 ShellExecute 之类的工具打开。即:
oHTTP = CreateObject("MSXML2.XMLHTTP.6.0")
oHTTP.Open("GET", 'https://homologacao.plugboleto.com.br/api/v1/boletos/impressa /lote/NIKLfYBWz',.F.)
oHTTP.setRequestHeader("content-type", "application/pdf")
oHTTP.Send()
Local lcFileName
lcFileName = Forcepath(Sys(2015)+'.pdf', Sys(2023))
Strtofile(oHttp.responseText, m.lcFileName)
Declare Long ShellExecute In "shell32.dll" ;
long HWnd, String lpszOp, ;
string lpszFile, String lpszParams, ;
string lpszDir, Long nShowCmd
ShellExecute(_vfp.HWnd,'',m.lcFileName,'','',1)
编辑:这不是一份工作MSXML2.XmlHttp。您只需下载 PDF 文件并打开它:
Local lcFileName, lcRemote
lcRemote = 'https://homologacao.plugboleto.com.br/api/v1/boletos/impressao/lote/NIKLfYBWz'
lcFileName = Forcepath(Sys(2015)+'.pdf', Sys(2023))
If (getFileFromURL(m.lcRemote, m.lcFileName) = 0)
Declare Long ShellExecute In "shell32.dll" ;
long HWnd, String lpszOp, ;
string lpszFile, String lpszParams, ;
string lpszDir, Long nShowCmd
ShellExecute(_vfp.HWnd,'',m.lcFileName,'','',1)
Endif
Procedure getFileFromURL
Lparameters tcRemoteFile,tcLocalFile
Declare Integer URLDownloadToFile In urlmon.Dll;
INTEGER pCaller, String szURL, String szFileName,;
INTEGER dwReserved, Integer lpfnCB
Return URLDownloadToFile(0, m.tcRemoteFile, m.tcLocalFile, 0, 0)
endproc