duancan8382 2010-01-08 10:42
浏览 48
已采纳

Web代理(PHP和curl),AJAX和多维关联$ _POST数组或$ _SERVER ['QUERY_STRING']?

I've got an html form that submits via AJAX (jquery Form Plugin) to a PHP Web Proxy on my server. The web proxy uses curl to POST to a third party script.

My html form has inputs with names like p[fname], p[lname], c[name], p[loc], p[loc][email], p[loc][email][detail]. The names are specified by the third party application.

When I use GET to submit the form to the web proxy, I can simply do the following to transmit the form data successfully to the third party script inside a curl request:

$postvars = $_SERVER['QUERY_STRING'];
curl_setopt ($session, CURLOPT_POSTFIELDS, $postvars);

Question #1: Is there anything 'wrong' with using GET to submit the form data to my web proxy? As I mentioned, it works fine, and requires less coding. $_SERVER['QUERY_STRING'] has exactly the data I need to pass to the third party via POST, in exactly the correct format.

Question #2: If there is a compelling reason to use POST to submit to my web proxy, what's the best way to loop through the multidimensional associative array in $_POST in order to build $postvars dynamically, without having to hard code any key values?

Note: The html form is not mission-critical and the data submitted by it goes into an approval cue in the third party service. It's not inserted directly into the production data.

  • 写回答

1条回答 默认 最新

  • dquoj04882 2010-01-08 11:44
    关注

    As the names already say, GET should be used if you only want to get data without changing data on the server side.
    Same way, POST should be used if the request changes data on the server side.

    So you should select the method depending on what your request does. Also note that URLs are of limited length so you cannot put e.g. an arbitrary amount of text into a GET parameter.

    And after reading your question completely (:-D) it seems that your request changes (in this case adds) data which means using POST is the more correct way. But as you only send it via GET to your proxy and then via POST to the other app, as long as it works, it is fine.
    It only depends on what type of data you send.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误