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 (将#修改为@)