大佬教程收集整理的这篇文章主要介绍了作为 JavaScript Blob 的一部分从客户端传递的 Guid 格式错误,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个 application/octet-stream
类型的 Blob,其中包含 JavaScript 字符串形式的 GUID
。这个 blob 是通过 WebSocket 接收的,然后我的 C# 应用程序将它输入到 MemoryStream 中以拆分出各个 blob 实体(字符串、数字、文件和 guID 等等)
上述功能按要求运行,但是 GuID 没有从 MemoryStream 正确重新构成,我不知道为什么?
更新:Js 端似乎被编码为 UTF8 字符串。在验证 blob 的其余部分时,我注意到 requestKey
,int
从内存流中读取为 '51' 的单个字节,UTF8 编码为值“3”(它最初是一个int 值 3)。使用 32 个流位将此应用于 GUID 问题后,我得到了正确的 guID。 buffer = new byte[32]; guID = new GuID(EnCoding.UTF8.GetString(buffer));
所以更新的问题是,我在 Js 方面做错了什么,没有将整个包作为单个连续的 byteArray。在对整个部件数组进行 blob 之前,我应该对部件数组中的每个项目进行 Blob 处理吗?)
JavaScript
var parts = [];
//"3F73B3E6-7351-416F-ACA3-AE639A3F587F"
parts.push(guID);
//Integer between 0 and 100
parts.push(requestKey);
//The length of the description in bytes
parts.push(new Blob([assetDescription]).sizE);
//"A brIEf description of the asset,the textual length varIEs."
parts.push(assetDescription);
//'data' is the result of a prior fetch("url").then(data => PackageAsset(data));
parts.push(data.arrayBuffer());
/*shortened for brevity,but it's sent off via websocket*/
wSocket.send((new Blob(parts,{type: "application/octet-stream"}));
C#
//Occurs after the WebSocket payload has been received and verifIEd
byte[] buffer;
int tokenSize = 16;
//Get the guID and the request key
using (MemoryStream memStream = new MemoryStream(data,tokenSize + Keys.requEST_KEY_SIZE)) {
buffer = new byte[tokenSize];
memStream.Read(buffer,tokenSizE);
//Not the GUID that was passed in
//"33374633-3342-3645-2d37-3335312d3431"
GuID recToken = new GuID(buffer);
buffer = new byte[Keys.requEST_KEY_SIZE];
memStream.Read(buffer,Keys.requEST_KEY_SIZE);
Keys.requestKey reqKey = (Keys.requestKey)Enum.ToObject(typeof(Keys.requestKey),buffer);
/*shortened for brevity,extracts the other parts*/
}
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的作为 JavaScript Blob 的一部分从客户端传递的 Guid 格式错误全部内容,希望文章能够帮你解决作为 JavaScript Blob 的一部分从客户端传递的 Guid 格式错误所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。