使用 C# 读取附加到 HTTP 扩展的 BLOB
Reading a BLOB that is appended to HTTP extension using C#
所以我正在使用第三方服务,让我可以编辑存储在服务器路径上的 XML
文件。现在,一旦我完成 XML
的编辑,我就将文件保存到本地内存存储,生成一个附加到 URL.
的 BLOB
示例:
blob:http://localhost/0e06af7a-a1a9-4bf1-a79a-78a1e107648f
其中 0e06af7a-a1a9-4bf1-a79a-78a1e107648f
是为当前编辑创建的标记。现在当我在浏览器中 运行 以上 URL 时,我可以看到:
我的问题是:如何使用 C# 读取上面的内容 URL,然后将内容保存到一个对象中,稍后我可以使用该对象上传到文件或云中。我试过使用 WebClient
:
WebClient client = new WebClient();
Stream stream = client.OpenRead("blob:http://localhost/0e06af7a-a1a9-4bf1-a79a-78a1e107648f");
StreamReader reader = new StreamReader(stream);
string str= reader.ReadToEnd();
但它给我一个错误,说 URL
不正确,应该以 HTTP
或 HTTPS
.
开头
编辑:我可以使用 JQuery:
将 blob 保存到文件中
var download = $('<a>Download ' + "file.xml" + '</a>').attr("href", "blob:http://localhost/0e06af7a-a1a9-4bf1-a79a-78a1e107648f");
download.attr("download", "file.xml");
这成功创建了一个名为 file.xml
的文件并下载了该文件。我希望将此 blob 内容保存在服务器端,以便将其发送到 Amazon S3
存储桶。
再次编辑:
所以,目前我已经将 XML
保存为一个字符串,我正试图通过 AJAX 将它发送到 C# 控制器,但是 运行 进入 500 内部服务器错误.
var xmlString = self.xml2Str(self.xmlState.xml);
//console.log(xmlString);
var blob = new Blob([xmlString], { type: "text/xml" });
console.log(blob);
var url = URL.createObjectURL(blob);
console.log(url);
var json = {
xmlString: xmlString
};
var test = JSON.stringify(json);
console.log(test);
try {
$.ajax({
url: BaseURL + "Home/SendXMLToS3",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: { "json": test},
type: "POST",
success: function (data) {
//TODO: Add whatever if you want to pass a notification back
alert("Done");
},
error: function (error) {
//TODO: Add some code here for error handling or notifications
alert("Not Done");
}
});
}
catch (err) {
console.log(err);
}
test
变量内容如下(来自控制台):
{"xmlString":"<nitf>\n <head>\n <docdata>\n <identified-content>\n <classifier id=\"box-geometry\" value=\"147,623,250,790\" />\n <classifier id=\"uuid\" value=\"Mv8XVAViEeqyc3SUunSxMg\" />\n </identified-content>\n </docdata>\n </head>\n <body>\n <body.head />\n <body.content>\n <p>\n <lang fontStyle=\"regular\" style=\".Bodylaser\">How is this different from Pegasus?</lang>\n </p>\n <p>\n <lang fontStyle=\"regular\" style=\".Bodylaser\">Pegasus could be installed on your phone without your knowledge through just a missed WhatsApp video call. In the case of the new breach, a user has to manually download the MP4 file sent to them before any malicious code can be run. The problem is not with WhatsApp’s end-to-end encryption feature here. Getting remote access to your phone is the equivalent of actually holding it in one’s hand. End-to-end encryption is meant to stop attackers from stealing or snooping on chats in between. So, unless someone has access to your device, they can’t actually read your chats, even if they intercept them.</lang>\n </p>\n </body.content>\n </body>\n</nitf>"}
还尝试设置默认 ASP.NET 默认启用请求验证以帮助防止 XSS 为 false。
[HttpPost]
[ValidateInput(false)]
public ActionResult SendXMLToS3(string json)
仍然存在相同的 500 错误:jquery.min.js:4 POST http://localhost/DEGit/Home/SendXMLToS3 500 (Internal Server Error)
在 h.send(c.hasContent&&c.data||null)
方法中。
我怎样才能:
- 在C#中读取生成的
blob
URL内容?
- 通过 AJAX 将
test
字符串发送到 C#?
- 大家还有什么建议。
谢谢
正如您在评论中所要求的那样:我制作了简单的控制器和 JS 代码,使用 ajax:
在控制器中命中 httppost
方法
- 控制器方法:
[HttpPost]
public JsonResult SendXMLToS3(string json)
{
return Json(new { Result = "PASS", Message = "testing SendXMLToS3" });
}
- JS代码:
<script type="text/javascript">
function myfunction() {
var test = { "xmlString": "<nitf>...</nitf>" };
$.ajax({
type: "post",
url: "/Home/SendXMLToS3",
dataType: "json",
data: { "json": test },
success: function (res) {
alert(res.Message);
},
error: function (res) {
//TODO: Add some code here for error handling or notifications
alert("Not Done");
}
});
}
</script>
调查结果:
contentType: "application/json; charset=utf-8",
行导致了内部 500 错误,如果将其删除,应该没问题。
所以我正在使用第三方服务,让我可以编辑存储在服务器路径上的 XML
文件。现在,一旦我完成 XML
的编辑,我就将文件保存到本地内存存储,生成一个附加到 URL.
示例:
blob:http://localhost/0e06af7a-a1a9-4bf1-a79a-78a1e107648f
其中 0e06af7a-a1a9-4bf1-a79a-78a1e107648f
是为当前编辑创建的标记。现在当我在浏览器中 运行 以上 URL 时,我可以看到:
我的问题是:如何使用 C# 读取上面的内容 URL,然后将内容保存到一个对象中,稍后我可以使用该对象上传到文件或云中。我试过使用 WebClient
:
WebClient client = new WebClient();
Stream stream = client.OpenRead("blob:http://localhost/0e06af7a-a1a9-4bf1-a79a-78a1e107648f");
StreamReader reader = new StreamReader(stream);
string str= reader.ReadToEnd();
但它给我一个错误,说 URL
不正确,应该以 HTTP
或 HTTPS
.
编辑:我可以使用 JQuery:
将 blob 保存到文件中var download = $('<a>Download ' + "file.xml" + '</a>').attr("href", "blob:http://localhost/0e06af7a-a1a9-4bf1-a79a-78a1e107648f");
download.attr("download", "file.xml");
这成功创建了一个名为 file.xml
的文件并下载了该文件。我希望将此 blob 内容保存在服务器端,以便将其发送到 Amazon S3
存储桶。
再次编辑:
所以,目前我已经将 XML
保存为一个字符串,我正试图通过 AJAX 将它发送到 C# 控制器,但是 运行 进入 500 内部服务器错误.
var xmlString = self.xml2Str(self.xmlState.xml);
//console.log(xmlString);
var blob = new Blob([xmlString], { type: "text/xml" });
console.log(blob);
var url = URL.createObjectURL(blob);
console.log(url);
var json = {
xmlString: xmlString
};
var test = JSON.stringify(json);
console.log(test);
try {
$.ajax({
url: BaseURL + "Home/SendXMLToS3",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: { "json": test},
type: "POST",
success: function (data) {
//TODO: Add whatever if you want to pass a notification back
alert("Done");
},
error: function (error) {
//TODO: Add some code here for error handling or notifications
alert("Not Done");
}
});
}
catch (err) {
console.log(err);
}
test
变量内容如下(来自控制台):
{"xmlString":"<nitf>\n <head>\n <docdata>\n <identified-content>\n <classifier id=\"box-geometry\" value=\"147,623,250,790\" />\n <classifier id=\"uuid\" value=\"Mv8XVAViEeqyc3SUunSxMg\" />\n </identified-content>\n </docdata>\n </head>\n <body>\n <body.head />\n <body.content>\n <p>\n <lang fontStyle=\"regular\" style=\".Bodylaser\">How is this different from Pegasus?</lang>\n </p>\n <p>\n <lang fontStyle=\"regular\" style=\".Bodylaser\">Pegasus could be installed on your phone without your knowledge through just a missed WhatsApp video call. In the case of the new breach, a user has to manually download the MP4 file sent to them before any malicious code can be run. The problem is not with WhatsApp’s end-to-end encryption feature here. Getting remote access to your phone is the equivalent of actually holding it in one’s hand. End-to-end encryption is meant to stop attackers from stealing or snooping on chats in between. So, unless someone has access to your device, they can’t actually read your chats, even if they intercept them.</lang>\n </p>\n </body.content>\n </body>\n</nitf>"}
还尝试设置默认 ASP.NET 默认启用请求验证以帮助防止 XSS 为 false。
[HttpPost]
[ValidateInput(false)]
public ActionResult SendXMLToS3(string json)
仍然存在相同的 500 错误:jquery.min.js:4 POST http://localhost/DEGit/Home/SendXMLToS3 500 (Internal Server Error)
在 h.send(c.hasContent&&c.data||null)
方法中。
我怎样才能:
- 在C#中读取生成的
blob
URL内容? - 通过 AJAX 将
test
字符串发送到 C#? - 大家还有什么建议。
谢谢
正如您在评论中所要求的那样:我制作了简单的控制器和 JS 代码,使用 ajax:
在控制器中命中httppost
方法
- 控制器方法:
[HttpPost]
public JsonResult SendXMLToS3(string json)
{
return Json(new { Result = "PASS", Message = "testing SendXMLToS3" });
}
- JS代码:
<script type="text/javascript">
function myfunction() {
var test = { "xmlString": "<nitf>...</nitf>" };
$.ajax({
type: "post",
url: "/Home/SendXMLToS3",
dataType: "json",
data: { "json": test },
success: function (res) {
alert(res.Message);
},
error: function (res) {
//TODO: Add some code here for error handling or notifications
alert("Not Done");
}
});
}
</script>
调查结果:
contentType: "application/json; charset=utf-8",
行导致了内部 500 错误,如果将其删除,应该没问题。