从cURL发布:HTTP_X_REQUESTED_WITH [英] Posting from cURL: HTTP_X_REQUESTED_WITH

查看:147
本文介绍了从cURL发布:HTTP_X_REQUESTED_WITH的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将表单程序化地发布到PHP表单处理脚本。有没有办法让我让表单处理脚本认为这篇文章是由ajax完成的?表单处理程序当前在$ _SERVER中检查HTTP_X_REQUESTED_WITH以实现特殊的仅ajax逻辑。我需要使用cURL发布到表单时执行的代码。

通过PHP cURL - http://www.php.net/manual/en/function.curl-setopt.php

  $ ch = curl_init(); 
curl_setopt($ ch,CURLOPT_HTTPHEADER,array(X-Requested-With:XMLHttpRequest));
$ result = curl_exec($ ch);
curl_close($ ch);


I'm programatically posting a form to a PHP form handling script. Is there a way for me to make the form handling script think that the post is being done by ajax? The form handler currently checks for HTTP_X_REQUESTED_WITH in $_SERVER to implement special ajax only logic. I need those codes executed when I post to the form using cURL.

解决方案

via PHP cURL - http://www.php.net/manual/en/function.curl-setopt.php

$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Requested-With: XMLHttpRequest"));
$result = curl_exec ($ch);
curl_close ($ch); 

这篇关于从cURL发布:HTTP_X_REQUESTED_WITH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆