热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

重定向POST请求并保留数据。可能?-RedirectPOSTrequestandkeepdata.Possible?

Myproblemissimple.Ineedtouploadafiledirectlytothecorrectserver(whichhascurrentlylo

My problem is simple. I need to upload a file directly to the correct server (which has currently low workload).

我的问题很简单。我需要将文件直接上传到正确的服务器(目前工作负载较低)。

Therefore I do:

所以我这样做:


then i print my form like

然后我打印我的表格像

"...

Now I would like to shift this step to when the upload starts, like so:

现在我想将此步骤转移到上传开始时,如下所示:

this url should do a redirect to the "real" server.

这个网址应该重定向到“真正的”服务器。

So that the upload page doesn't slow down loading and I have static html code that I can cache, embed etc...

所以上传页面不会减慢加载速度,我有静态HTML代码,我可以缓存,嵌入等...

Problem is that this works perfetly fine with get requests but not with post requests.

问题是,这对于get请求很好,但不适用于post请求。

The request seems like to get transformed into a get request when redirecting using the location header. All post data is lost.

当使用location头重定向时,请求似乎转换为get请求。所有帖子数据都会丢失。

Is this impossible or am I doing it wrong? And yes, I considered a remote dynamic Javascript that prints the html code with the correct server in the first place. I would rather like not to do that...

这是不可能的还是我做错了?是的,我考虑了一个远程动态Javascript,它首先用正确的服务器打印html代码。我宁愿不这样做......

any ideas? Maby alternative uplod techniques?

有任何想法吗? Maby替代uplod技术?

edit:

this is the exact html code i use:

这是我使用的确切html代码:

 

File to upload: 
Notes about the file:

to upload the file!

this is the redirect code i use:

这是我使用的重定向代码:

if($_GET["action"] == "target") {
    header("Location: http://storage.ivana.2x.to/rest.php?action=test");
}

this is the output code i use to see the results:

这是我用来查看结果的输出代码:

if($_GET["action"] == "test") {
    echo "
";
    var_dump($_POST);
    var_dump($_GET);
    var_dump($_FILES);
}

the result when uploading a small file looks like:

上传小文件时的结果如下:

array(0) {
}
array(1) {
  ["action"]=>
  string(4) "test"
}
array(0) {
}

4 个解决方案

#1


2  

If you really want to load balance through the code while potentially caching the page with the upload form, first select the default download server (url); then, onSubmit call the server and find the best upload target and adjust the action attribute accordingly.

如果您真的希望通过代码加载平衡,同时可能使用上传表单缓存页面,请首先选择默认下载服务器(url);然后,onSubmit调用服务器并找到最佳上传目标并相应地调整action属性。

With this method, users who do not activate JS still get what they want, users with JS enabled get the better upload target, and you can still cache. Additionally, the timing of the cache request could potentially be more opportunistic, since the URL request will occur very shortly before the actual upload.

使用此方法,不激活JS的用户仍然可以获得他们想要的内容,启用了JS的用户可以获得更好的上载目标,并且您仍然可以缓存。此外,缓存请求的时间可能更具机会性,因为URL请求将在实际上载之前不久发生。

The only hitch will be the call to get the URL, which you can more easily performance tune (I imagine) than the process you are describing above. Uploading a file twice through a header directive and/or cURL call don't seem like a good tradeoff for caching a single html file, IMO. But I don't know what you're up against, either.

唯一的障碍是获取URL的调用,您可以比上面描述的过程更容易地进行性能调整(我想象)。通过头指令和/或cURL调用两次上传文件似乎不是缓存单个html文件IMO的良好权衡。但我也不知道你的反对意见。

If you don't want to heavily administer the server environment and introduce load balancing, this is the option I would suggest.

如果您不想大量管理服务器环境并引入负载平衡,这是我建议的选项。

Note, also, I am not a server administrator by trade.

另请注意,我不是贸易服务器管理员。

#2


2  

You could try returning a code 302 (temporary moved), not 100% that would let your browser post the data to the changed url though, but it's worth something to check out.

您可以尝试返回代码302(临时移动),而不是100%会让您的浏览器将数据发布到更改后的网址,但是值得一试。

[Edit]

According to this wikipedia article, the POST data would be converted to GET, which probably won't work for a file upload.

根据这篇维基百科文章,POST数据将转换为GET,这可能不适用于文件上传。

#3


1  

This is not a good solution. The file will be uploaded in it's entirety before the PHP script is even started. This means that if you succeed with what you're trying to do the client will have to upload the file twice!

这不是一个好的解决方案。在PHP脚本启动之前,文件将完整上传。这意味着如果您成功完成了尝试,客户端必须上传文件两次!

I recommend that you try to figure out which server to send the request to when you're creating the form, so the action attribute in the form tag will point directly to the lesser loaded machine.

我建议您在创建表单时尝试确定将请求发送到哪个服务器,因此表单标记中的action属性将直接指向较少加载的计算机。

Or even better: use a serverside loadbalancer and make your HTTP infrastructure transparent to the browser. This is essentially a sysadmin problem.

甚至更好:使用服务器端负载均衡器,使您的HTTP基础架构对浏览器透明。这本质上是一个系统管理员问题。

#4


0  

i might be wrong but.. your form's action points to ?action=target and in your rest.php you do a header to "?action=test" well of course you wont find your $POST nor your $FILES!... a header() does not send those variables..

我可能错了,但是...你的表格的动作指向?action = target,在你的rest.php你做一个标题“?action = test”当然你不会找到你的$ POST或你的$ FILES!... header()不发送那些变量..

if you want to send your post and your file to a differente location you'll need to use the cUrl library.. but it wont be easy :)

如果你想将你的帖子和你的文件发送到一个不同的位置,你需要使用cUrl库..但它不会很容易:)

Good Luck


推荐阅读
  • 本文介绍了Web学习历程记录中关于Tomcat的基本概念和配置。首先解释了Web静态Web资源和动态Web资源的概念,以及C/S架构和B/S架构的区别。然后介绍了常见的Web服务器,包括Weblogic、WebSphere和Tomcat。接着详细讲解了Tomcat的虚拟主机、web应用和虚拟路径映射的概念和配置过程。最后简要介绍了http协议的作用。本文内容详实,适合初学者了解Tomcat的基础知识。 ... [详细]
  • Nginx使用AWStats日志分析的步骤及注意事项
    本文介绍了在Centos7操作系统上使用Nginx和AWStats进行日志分析的步骤和注意事项。通过AWStats可以统计网站的访问量、IP地址、操作系统、浏览器等信息,并提供精确到每月、每日、每小时的数据。在部署AWStats之前需要确认服务器上已经安装了Perl环境,并进行DNS解析。 ... [详细]
  • 本文详细介绍了SQL日志收缩的方法,包括截断日志和删除不需要的旧日志记录。通过备份日志和使用DBCC SHRINKFILE命令可以实现日志的收缩。同时,还介绍了截断日志的原理和注意事项,包括不能截断事务日志的活动部分和MinLSN的确定方法。通过本文的方法,可以有效减小逻辑日志的大小,提高数据库的性能。 ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • 搭建Windows Server 2012 R2 IIS8.5+PHP(FastCGI)+MySQL环境的详细步骤
    本文详细介绍了搭建Windows Server 2012 R2 IIS8.5+PHP(FastCGI)+MySQL环境的步骤,包括环境说明、相关软件下载的地址以及所需的插件下载地址。 ... [详细]
  • Linux重启网络命令实例及关机和重启示例教程
    本文介绍了Linux系统中重启网络命令的实例,以及使用不同方式关机和重启系统的示例教程。包括使用图形界面和控制台访问系统的方法,以及使用shutdown命令进行系统关机和重启的句法和用法。 ... [详细]
  • 开发笔记:加密&json&StringIO模块&BytesIO模块
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了加密&json&StringIO模块&BytesIO模块相关的知识,希望对你有一定的参考价值。一、加密加密 ... [详细]
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • 图解redis的持久化存储机制RDB和AOF的原理和优缺点
    本文通过图解的方式介绍了redis的持久化存储机制RDB和AOF的原理和优缺点。RDB是将redis内存中的数据保存为快照文件,恢复速度较快但不支持拉链式快照。AOF是将操作日志保存到磁盘,实时存储数据但恢复速度较慢。文章详细分析了两种机制的优缺点,帮助读者更好地理解redis的持久化存储策略。 ... [详细]
  • http:my.oschina.netleejun2005blog136820刚看到群里又有同学在说HTTP协议下的Get请求参数长度是有大小限制的,最大不能超过XX ... [详细]
  • 计算机存储系统的层次结构及其优势
    本文介绍了计算机存储系统的层次结构,包括高速缓存、主存储器和辅助存储器三个层次。通过分层存储数据可以提高程序的执行效率。计算机存储系统的层次结构将各种不同存储容量、存取速度和价格的存储器有机组合成整体,形成可寻址存储空间比主存储器空间大得多的存储整体。由于辅助存储器容量大、价格低,使得整体存储系统的平均价格降低。同时,高速缓存的存取速度可以和CPU的工作速度相匹配,进一步提高程序执行效率。 ... [详细]
  • 本文介绍了计算机网络的定义和通信流程,包括客户端编译文件、二进制转换、三层路由设备等。同时,还介绍了计算机网络中常用的关键词,如MAC地址和IP地址。 ... [详细]
  • 本文介绍了通过ABAP开发往外网发邮件的需求,并提供了配置和代码整理的资料。其中包括了配置SAP邮件服务器的步骤和ABAP写发送邮件代码的过程。通过RZ10配置参数和icm/server_port_1的设定,可以实现向Sap User和外部邮件发送邮件的功能。希望对需要的开发人员有帮助。摘要长度:184字。 ... [详细]
  • 本文介绍了在使用Python中的aiohttp模块模拟服务器时出现的连接失败问题,并提供了相应的解决方法。文章中详细说明了出错的代码以及相关的软件版本和环境信息,同时也提到了相关的警告信息和函数的替代方案。通过阅读本文,读者可以了解到如何解决Python连接服务器失败的问题,并对aiohttp模块有更深入的了解。 ... [详细]
  • Python瓦片图下载、合并、绘图、标记的代码示例
    本文提供了Python瓦片图下载、合并、绘图、标记的代码示例,包括下载代码、多线程下载、图像处理等功能。通过参考geoserver,使用PIL、cv2、numpy、gdal、osr等库实现了瓦片图的下载、合并、绘图和标记功能。代码示例详细介绍了各个功能的实现方法,供读者参考使用。 ... [详细]
author-avatar
lin悟_462
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有