如何解决ASP Classic 重新发布发布的数据
我正在使用 AJAX 将上传的文件发布到经典 ASP,我需要能够将发布流重新发布到另一个站点。
我可以验证来自 AJAX 请求的发布数据是否正确。我可以读取文件并将它们保存在本地服务器上。我可以将 AJAX 网址更改为“重新发布”网址,并且效果很好。
问题只是读取发布的数据并重新发布。
let data = formData; //all the files we are uploading
$.ajax({
url: `MyMultiFileHandler.asp`,cache: false,contentType: false,processData: false,enctype: 'multipart/form-data',data: data,type: `POST`,}).done(function(data) {
console.log(`data: `,data);
}).fail(function(xhr,textStatus,errorThrown) {
console.log(xhr,errorThrown);
}).always(function() {
});
MyMultiFileHandler.asp
dim postData: postData=request.Form
Set ServerXmlHttp = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
ServerXmlHttp.open "POST","https://example.com",false
'ServerXmlHttp.setRequestHeader "Content-Type","application/x-www-form-urlencoded"
ServerXmlHttp.setRequestHeader "Content-Type","multipart/form-data"
ServerXmlHttp.setRequestHeader "Content-Length",Len(postData)
ServerXmlHttp.send postData
If ServerXmlHttp.status = 200 Then
TextResponse = ServerXmlHttp.responseText
response.write TextResponse ' Success! 0 files uploaded!
Else
response.write err.description & "fault 6"
response.end
End If
Set ServerXmlHttp = Nothing
编辑添加被调用的控制器 这是在“存储库”服务器上调用的控制器和函数:
[HttpPost]
//[ValidateAntiForgeryToken]
public ActionResult Upload(string folderpath,IEnumerable<HttpPostedFileBase> imgfiles)
{
folderpath = !String.IsNullOrEmpty(folderpath) ? folderpath.Replace("|","\\") : "";
bool exists = System.IO.Directory.Exists(Server.MapPath($"/imagerepository/{folderpath}"));
if(!exists)
System.IO.Directory.CreateDirectory(Server.MapPath($"/imagerepository/{folderpath}"));
int count = 0;
var fileName = "";
if (imgfiles != null)
{
foreach (var file in imgfiles)
{
if (file != null && file.ContentLength > 0)
{
fileName = file.FileName;
var path = Path.Combine(Server.MapPath($"/imagerepository/{folderpath}"),fileName);
//return new JsonResult { Data = "Successfully " + count + " file(s) uploaded: " + fileName + " path " +path};
file.SaveAs(path);
count++;
}
}
}
return new JsonResult { Data = "Successfully upoaded " + count + " file(s)"};
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。