我正在使用经典的 asp 和 JSON 将 html 转换为 pdf。我使用以下方式发送请求:
''Convert output to pdf
varURL = "https://" & varServerLive & "/import/" & fileName
postURL = "https://v2.convertapi.com/convert/htm/to/pdf?Secret=SECRET_KET&File=" & varURL & "&StoreFile=true"
parmToSend = "{""Parameters"":[{""Name"":""File"",""FileValue"":{""url"": """ & varURL & """}}," & _
"{""Name"":""WebHook"",""Value"":""" & varURL & """}" & _
"]}"
Set ServerXmlHttp = Server.CreateObject("MSXML2.XMLHTTP.6.0")
ServerXmlHttp.open "POST", postURL
ServerXmlHttp.setRequestHeader "Accept", "application/json"
ServerXmlHttp.setRequestHeader "Content-Type", "application/json"
ServerXmlHttp.send parmToSend
''Get response
responseText = ServerXmlHttp.responseText
response.write(responseText)
set myJson = JSON.parse(responseText)
varFileUrl = myJson.Files.Url
response.write(varFileUrl)
我收到以下回复:
回复文字:
{"ConversionCost":2,"Files":[{"FileName":"54-25062020177.pdf","FileExt":"pdf","FileSize":48596,"FileId":"542c6f079fe5722bdbac2f73f84652d3","Url":"https://v2.convertapi.com/d/542c6f079fe5722bdbac2f73f84652d3/54-25062020177.pdf"}]}
这一切都很好,但是当我尝试返回 fileURL 时,出现错误:
Microsoft VBScript 运行时错误“800a01b6”
对象不支持此属性或方法:'url'
/docs/members/cert.asp,第 122 行
您是否发现网址未返回的任何原因?我是否正确调用了 url(例如 myJson.Files.Url)?
任何帮助将不胜感激。
已排序。我需要指定数组中的位置,这很奇怪,因为我从来不需要在其他函数中执行此操作。
varFileUrl = myJson.Files.[0].Url
我建议使用
content-type:application/octet-stream
,你会得到文件流而不是JSON,之后你可以轻松地将流转储到文件中。使用蒸汽响应的优点是:
响应大小将比 JSON 小约 30%,因为 JSON 文件 数据需要以 Base64 编码,
您可以分块读取数据。
如果您仍然喜欢使用 JSON,则从请求中删除 StoreFile=true,您将获得文件数据而不是 URl,使用 base64 对其进行解码并写入文件。您将向服务器保存一个请求。
ConvertApi 使用 json 这是将 PNG 转换为 SVG 最简单的方法:
jQuery(document).ready(function(){
$.ajax({
dataType: "JSON",
url: 'https://v2.convertapi.com/convert/png/to/svg?Secret=SECRET TOKEN HERE',
type:"POST",
data: {File:'IMAGE URL HERE',StoreFile:true},
success: function(res){
//console.log(res)
console.log(res.Files[0].Url)
}
});
});