简体   繁体   English

vb .net base64无法正确编码

[英]vb .net base64 not encoding correctly

I have looked all over and none of the issues I am finding fixes my issue. 我到处都看过了,发现的问题都没有解决我的问题。

I have a program that sends json strings to a server. 我有一个程序可以将json字符串发送到服务器。 I upload and download files. 我上传和下载文件。 They are between a vb client and php server. 它们位于vb客户端和php服务器之间。 I can go from the server to the client just fine but when I try to send a file to the server the base64 is invalid. 我可以从服务器转到客户端,但是当我尝试将文件发送到服务器时,base64无效。

Here is my code on the vb side. 这是我在vb端的代码。

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

Dim base64String As String = Convert.ToBase64String(bytes)  

If I send a text file and decode it manually 80% of the file is there then it just goes to garbage. 如果我发送一个文本文件并手动对其进行解码,则文件中的80%都在那里,那么它就会变成垃圾。 Is there some other setting for convert.tobase64String that I'm missing? 我还缺少其他convert.tobase64String设置吗?

Here is the base64 inside the json 这是json内的base64

VGhpcyBrbm93bGVkZ2UgYmFzZSBhcnRpY2xlIHNob3VsZCBoYXZlIHRoZSBtYWludGVuYW5jZSBwbGFuIHRoYXQgRGF2aWQgaXMgcmVmZXJlbmNpbmcuDQoNCmh0dHBzOi8vc3VwcG9ydGNlbnRlci5lbWRzLmNvbS9hcnRpY2xlcy9Ucm91Ymxlc2hvb3RpbmcvSG93LWRvLUktcmVpbmRleC1teS1Tb2x1dGlvbi1TZXJpZXMtODAtZGF0YWJhc2Umcz1yZWluZGV4JTIwJnA9MSANCg0KSWYgeW91IGhhdmUgYW55IHF1ZXN0aW9ucyBhYm91dCBpdCBwbGVhc2UgZmVlbCBmcmVlIHRvIGdpdmUgdXMgYSBjYWxsIGF0IHRoZSBJVCBkZXBhcnRtZW50ICgxLTgwMC01NjUtNTU2NCBvcHRpb24gMikNCg0KLUFydA0KDQogICAgRGVjZW1iZXIgNSwgMjAxNyDCtyBMaWtlMCDCtyBEaXNsaWtlMCDCtyBGbGFnDQoNCkNhc2V5IFdpbGxpYW1zQ2FzZXkgV2lsbGlhbXMNCkh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dSdyZSBzdGlsbCBsb29raW5nIGZvciBhbiBhbnN3ZXIgLSB5b3Ugc2hvdWxkIE5FVkVSIFNocmluayB0aGUgRGF0YWJhc2UgdW5sZXNzIGFic29sdXRlbHkgbmVlZGVkLiANCg0KSGVyZSBpcyBhIGNvcnJlY3QgbGlzdCBvZiBNYWludGVuYW5jZSBQbGFucyBhbmQgaG93IG9mdGVuIHRoZSBzaG91bGQgcnVuOg0KQmFja3VwIExvZyBGaWxlcyBvZiBhbGwgREI6IEV2ZXJ5IDMwIE1pbnV0ZXMNClByaW1hcnkgTWFpbnRlbmFuY2UgUGxhbjogQ2hlY2sgRGF0YWJhc2UgSW50ZWdyaXR5PlJl YnVpbGQgSW5kZXg QmFjayBVcCAoRnVsbCkgLSBFdmVyeSBkYXkgaWYgcG9zc2libGUsIGFmdGVyIGhvdXJzLg0KIA== YnVpbGQgSW5kZXg QmFjayBVcCAoRnVsbCkgLSBFdmVyeSBkYXkgaWYgcG9zc2libGUsIGFmdGVyIGhvdXJzLg0KIA ==

Here is the textfile that made it. 这是创建它的文本文件。

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.

Here is what comes out on the server side 这是服务器端显示的内容

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

You can use Uri.EscapeDataString() to encode your Base64 string as body data. 您可以使用Uri.EscapeDataString()将Base64字符串编码为主体数据。 This will encode the slash as %2F and should be automatically decoded by the server. 这会将斜杠编码为%2F并且应由服务器自动解码。

Dim encodedString As String = Uri.EscapeDataString(base64String)

EDIT: 编辑:

For data longer than 65520 chars you can use WebUtility.UrlEncode() instead until the Uri class's problem is fixed (if it ever will be), but note that WebUtility too has some quirks of its own . 对于长度超过65520个字符的数据,可以改用WebUtility.UrlEncode()直到解决Uri类的问题(如果可以解决),但请注意, WebUtility也有其自身的一些怪癖

Dim encodedString As String = WebUtility.UrlEncode(base64String)

Uri.EscapeDataString() is the most RFC-compliant method today and thus is the preferred solution (when possible). Uri.EscapeDataString()是当今最符合RFC的方法,因此是首选的解决方案(如果可能)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM