vb .net base64无法正确编码

时间:2019-01-24 20:10:10

标签: php .net json vb.net base64

我已经看了很多遍,发现的问题都没有解决我的问题。

我有一个程序可以将json字符串发送到服务器。我上传和下载文件。它们位于vb客户端和php服务器之间。我可以从服务器转到客户端,但是当我尝试将文件发送到服务器时,base64无效。

这是我在vb上的代码。

Dim bytes As Byte()
bytes = System.IO.File.ReadAllBytes(filename)

Dim base64String As String = Convert.ToBase64String(bytes)  

如果我发送文本文件并手动对其进行解码,则文件的80%在那里,那么它就会变成垃圾。我还缺少针对convert.tobase64String的其他设置吗?

这是json中的base64

  

VGhpcyBrbm93bGVkZ2UgYmFzZSBhcnRpY2xlIHNob3VsZCBoYXZlIHRoZSBtYWludGVuYW5jZSBwbGFuIHRoYXQgRGF2aWQgaXMgcmVmZXJlbmNpbmcuDQoNCmh0dHBzOi8vc3VwcG9ydGNlbnRlci5lbWRzLmNvbS9hcnRpY2xlcy9Ucm91Ymxlc2hvb3RpbmcvSG93LWRvLUktcmVpbmRleC1teS1Tb2x1dGlvbi1TZXJpZXMtODAtZGF0YWJhc2Umcz1yZWluZGV4JTIwJnA9MSANCg0KSWYgeW91IGhhdmUgYW55IHF1ZXN0aW9ucyBhYm91dCBpdCBwbGVhc2UgZmVlbCBmcmVlIHRvIGdpdmUgdXMgYSBjYWxsIGF0IHRoZSBJVCBkZXBhcnRtZW50ICgxLTgwMC01NjUtNTU2NCBvcHRpb24gMikNCg0KLUFydA0KDQogICAgRGVjZW1iZXIgNSwgMjAxNyDCtyBMaWtlMCDCtyBEaXNsaWtlMCDCtyBGbGFnDQoNCkNhc2V5IFdpbGxpYW1zQ2FzZXkgV2lsbGlhbXMNCkhleSBKaW0sDQoNCkkga25vdyB0aGlzIGlzIHN1cGVyIG9sZCwgYnV0IGlmIHlvdSdyZSBzdGlsbCBsb29raW5nIGZvciBhbiBhbnN3ZXIgLSB5b3Ugc2hvdWxkIE5FVkVSIFNocmluayB0aGUgRGF0YWJhc2UgdW5sZXNzIGFic29sdXRlbHkgbmVlZGVkLiANCg0KSGVyZSBpcyBhIGNvcnJlY3QgbGlzdCBvZiBNYWludGVuYW5jZSBQbGFucyBhbmQgaG93IG9mdGVuIHRoZSBzaG91bGQgcnVuOg0KQmFja3VwIExvZyBGaWxlcyBvZiBhbGwgREI6IEV2ZXJ5IDMwIE1pbnV0ZXMNClByaW1hcnkgTWFpbnRlbmFuY2UgUGxhbjogQ2hlY2sgRGF0YWJhc2UgSW50ZWdyaXR5P lJlYnVpbGQgSW5kZXg QmFjayBVcCAoRnVsbCkgLSBFdmVyeSBkYXkgaWYgcG9zc2libGUsIGFmdGVyIGhvdXJzLg0KIA ==

这是创建它的文本文件。

This knowledge base article should have the maintenance plan that David is referencing.

https://supportcenter.emds.com/articles/Troubleshooting/How-do-I-reindex-my-Solution-Series-80-database&s=reindex%20&p=1 

If you have any questions about it please feel free to give us a call at the IT department (1-800-565-5564 option 2)

-Art

    December 5, 2017 · Like0 · Dislike0 · Flag

Casey WilliamsCasey Williams
Hey Jim,

I know this is super old, but if you're still looking for an answer - you should NEVER Shrink the Database unless absolutely needed. 

Here is a correct list of Maintenance Plans and how often the should run:
Backup Log Files of all DB: Every 30 Minutes
Primary Maintenance Plan: Check Database Integrity>Rebuild Index>Back Up (Full) - Every day if possible, after hours.

这是服务器端显示的内容

This knowledge base article should have the maintenance plan that David is referencing.

https://supportcenter.emds.com/articles/Troubleshooting/How-do-I-reindex-my-Solution-Series-80-database&s=reindex%20&p=1

If you have any questions about it please feel free to give us a call at the IT department (1-800-565-5564 option 2)

-Art

    December 5, 2017 · Like0 · Dislike0 · Flag

Casey WilliamsCasey Williams Hey Jim,

I know this is super old, but if you're still looking for an answer - you should NEVER Shrink the Database unless absolutely needed.

Here is a correct list of Maintenance Plans and how often the should run: Backup Log Files of all DB: Every 30 Minutes Primary Maintenance Plan: Check Database Integrity>Rebuild Indexbase64: invalid input

1 个答案:

答案 0 :(得分:0)

您可以使用Uri.EscapeDataString()将Base64字符串编码为主体数据。这样会将斜杠编码为%2F,并应由服务器自动解码。

Dim encodedString As String = Uri.EscapeDataString(base64String)

编辑:

对于长度超过65520个字符的数据,可以改用WebUtility.UrlEncode(),直到解决Uri类的问题(如果有的话),但请注意,WebUtility也有{{3 }}。

Dim encodedString As String = WebUtility.UrlEncode(base64String)

Uri.EscapeDataString()是当今最符合RFC的方法,因此是首选的解决方案(如果可能)。