URL 请求将 POST 数据添加到查询字符串

发布于 2024-08-12 10:21:26 字数 569 浏览 2 评论 0原文

我正在使用 ExtJS 将 Ajax 请求发送到服务器上的 PHP 页面,希望将参数作为 POST 变量而不是在查询字符串中发送。

由于我们的代理服务器之一出现缓存问题,因此我在查询字符串中包含了一个随机令牌。

Ext.Ajax.request({
url: 'ajax.php?action=test&randToken=' + generateRandomToken(),
scope: this,
method: 'POST',
success: ajaxSuccess,
failure: ajaxFailure,
params:
{
    param1: 'test',
    param2: 'data',
}});

当我在本地(在 Vista 盒子上)运行上面的代码时,它可以工作,并且使用 Fiddler 检查流量,一切看起来都很好。

然而,当在我们的 Ubuntu 临时服务器(运行 Zend 服务器)上运行时,所有 ajax 请求也会将 POST 数据放入查询字符串中。

我什至不知道从哪里开始寻找造成这种情况的原因。它是网络上的代理或其他东西,或者可能是临时服务器上的设置?

I am using ExtJS to send an Ajax request to a PHP page on a server, wanting to send the parameters as POST variables rather than in the querystring.

I have included a random token in the querystring since we were having caching issues on one of our proxy servers.

Ext.Ajax.request({
url: 'ajax.php?action=test&randToken=' + generateRandomToken(),
scope: this,
method: 'POST',
success: ajaxSuccess,
failure: ajaxFailure,
params:
{
    param1: 'test',
    param2: 'data',
}});

The code above works when I run it locally (on a Vista box), and checking the traffic using Fiddler everything appears fine.

When running on our Ubuntu staging server (running Zend server) however, all the ajax requests put the POST data into the querystring as well.

I do not even know where to begin looking for what is causing this. Is it a proxy or something on the network, or maybe a setting on the staging server?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

歌入人心 2024-08-19 10:21:26

尝试将所有参数放入 POST 中。您不应该在缓存方面遇到任何问题,因为 POST 不应该被缓存。

Ext.Ajax.request({
  url: 'ajax.php',
  scope: this,
  method: 'POST',
  success: ajaxSuccess,
  failure: ajaxFailure,
  params: {
    action: 'test',
    param1: 'test',
    param2: 'data'
  }
});

还可以尝试将查询字符串上的所有参数作为 GET 传递。如果您担心安全性,请注意,POST 和 GET 都通过 HTTP 传递,如果流量未使用 SSL 加密,很容易被嗅探。

Ext.Ajax.request({
  url: 'ajax.php?' + 
    Ext.urlEncode({
      action: 'test',
      randToken: generateRandomToken(),
      param1: 'test',
      param2: 'data'
    }),
  scope: this,
  method: 'GET',
  success: ajaxSuccess,
  failure: ajaxFailure
});

最后,尝试从 params 哈希中删除尾随逗号。某些浏览器(IE)在 js 中保留尾随逗号时会出现问题。

Try putting all your params into the POST. You shouldn't have any trouble with caching, since POSTs are not supposed to be cached.

Ext.Ajax.request({
  url: 'ajax.php',
  scope: this,
  method: 'POST',
  success: ajaxSuccess,
  failure: ajaxFailure,
  params: {
    action: 'test',
    param1: 'test',
    param2: 'data'
  }
});

Also try passing all params on the query string as a GET. If you're worried about security, note that both POSTs and GETs are passed over HTTP and are easily sniffed if traffic is not encrypted with SSL.

Ext.Ajax.request({
  url: 'ajax.php?' + 
    Ext.urlEncode({
      action: 'test',
      randToken: generateRandomToken(),
      param1: 'test',
      param2: 'data'
    }),
  scope: this,
  method: 'GET',
  success: ajaxSuccess,
  failure: ajaxFailure
});

And finally, try removing that trailing comma from the params hash. Some browsers (IE) have a fit when trailing commas are left in the js.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文