我正在尝试将base64字符串转换为我的Web服务中的pdf但由于某种原因它无法正常工作,我的网络服务器返回错误的请求。最后4行引起了这个问题。
我已经跟随了一堆例子并且到目前为止
Dim base64file As String = "iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAB/lBMVEX///+VlZWZmZmRlpaTlpaTlZaSlZaTk5ORlZWTlZWTlZaSmJj///+TlpaTlZaTlZaUlJSAgICSlZWTlJaTlZaTlpaOjo6SlZeTlZaTlZaUlJaPj4+TlZWTlZaTlZeTlZeVlZWUlZaWlpaUlZWTlpaTlZaWlpaTlZeTlZaTlZaTlpaZmZmUlZaVlZWTlZaTlZeUlJiSlZaTlZaSlJaWlpaTlZaTlZaPmZmTlZaTlpaVlZWSlZaVlZWSkpKTlZaTlZWTlJaTlZaTlpaSkpKUlZaAgICLi4uTlJaTlZaTlpaAqqqUlJeTlZaTlZeVlZWUlpaTlZaUlZWUlJSfn5+UlpaSlpaTlZaUlZWRl5eQlpaTlZaSl5eUlZWZmZmTlZeTlZaTlZaUlpaUlJeTlZaSlpaTlZWUlZaTlZWTlZeSlZWTlZWTk5OUlpaTlpaTlJaSlJaOnJyJnZ2TlZWUlJiSlZeSkpKSlZWTlpaSlJeTlZaTlJaXl5eTlJaSlJaVlZWTlpaTlZaUlZaSkpiTlJaTk5iTlZeUlZWUlZeTlZWTk5mTlZWTlZaUlJaTlpaTlZaUlJSUlJSTlZaTlZaSlZeTlZaQkJuUlJSTlZaTlZaTlZWVlZWSlZeTlZaTlJaUlJeTlZWUlpaUlJSTlZaTlZeSlZWTlZWTlZWVlZWTlZYAAABfkBHsAAAAqHRSTlMAHQozrP3RGkG64ioBUMjvPgRe1fhVCWzg/nAQe+qQiRjyIpjc7i6m/OZoBdg8tHhFw/aIEfuXGdqnJLcwFc/GydNODt8CC73pbQZR8X0MX/eMEwiDRNm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cq8cpbFR3vcKOaXKy5cYg2qUrl4j73qd3Yp2GmtnF3+drOzaVQmrOQPE8A0yT2726MQ9qfYyMdRNMlFuhMknowG5CemQGBtXxWXDcnC4TGXGx8hjm3xbigwQb90mW9F6J/XZehdiZMAHYnBXvnnvtJLF376lSMUGKE3QrbjnkxWTZBdHJ+Ww7x5d/MR0L6UxIFtxnxzegyQ+BHiEjwEe4yOAh5h8QA70fljTpTVAfEJLt3IEnkZlg+hTiD2jpf1Er2INupzMWT2nl5v3BcoG+ILeIIHnjCTO/ebrfsmEpVevI0lUDTAZef1KYgTJKUMxFjIviNHUjwrFAM1RJugeE7QCjHjeIA/VgMHbdy4Qo2LSltlAmmiA9HjflMlgIAAzwvTh40wGnz5DRuR+iaYz6P9amjmf4Nt3sYE/+z8dRY1Ggx81WacTBH/aWYPQr+Bs8gn6huKaQbyjZZbpFFNJ1aB2ag7pFGOJ3wC/E3/mmE7gIrfLoGvu+f8I/gKO8wApeMN4xQAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAxNi0wMy0yOVQxODo0NzoyNCswMjowMCvzrPoAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMTYtMDMtMjlUMTg6NDc6MjQrMDI6MDBarhRGAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAAABJRU5ErkJggg=="
Dim bytes As Byte() = Convert.FromBase64String(base64file)
Dim stream As New FileStream("c:\Users\me\Desktop\itworks.pdf", FileMode.CreateNew)
stream.Write(bytes, 0, bytes.Length)
stream.Close()
opResult.success = True
我做错了什么?
答案 0 :(得分:0)
正如其他人提到的那样,你应该在代码中添加日志以找出错误。
这有一些不错的建议: Where does Console.WriteLine go in ASP.NET?
否则,您可以在错误的代码周围添加try-catch,然后将异常打印到日志中。
我假设日志会在浏览器中显示,就像JS中的console.log一样。
如果您运行chrome,只需启动开发人员工具,并在您设置代码时找到您的控制台。这样,您可能会获得有关错误的更多信息。
此msdn URL包含有关try-catches的一些信息: https://msdn.microsoft.com/en-us/library/f9shkfdd.aspx
但基本上这个想法是你应该使用类似的东西:
Try
'Paste the code you are trying
Catch ex As Exception
'Add the log of your choice. In JS it would be Console.log(ex.message)
End Try