通过 PHP/Curl 将 HTML 表单传递到 JSP 页面...传递未发生

发布于 2024-12-07 16:50:40 字数 1581 浏览 0 评论 0原文

我有一个 HTML 表单,正在提交到 PHP 页面。 PHP 页面需要验证验证码,然后将表单值传递到 JSP 页面。我无法控制 JSP 页面。验证码运行良好。我的 PHP 页面中出现了一些问题,因为当它加载 JSP 页面上的信息时,目标页面的 CSS 和标头未加载,并且表单数据未传递。我无法访问 JSP 页面。有什么想法吗?

顺便说一句,验证码验证工作正常,如果我将其直接传递到 JSP 页面,HTML 工作正常:

 <?php
  require_once('recaptchalib.php');
  $privatekey = "privatekeyhere";
  $resp = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);

  if (!$resp->is_valid) {
    // What happens when the CAPTCHA was entered incorrectly
    die ("<p align='center'>The reCAPTCHA wasn't entered correctly. Please go back and try it again." .
         "(reCAPTCHA said: " . $resp->error . ")</p>");
  } else {


  $ipaddress = $_SERVER["REMOTE_ADDR"];
  $fname = $_POST['fname'];
  $address = $_POST['address'];
  $city = $_POST['city'];
  $state = $_POST['state'];
  $zip = $_POST['zip'];
  $phone = $_POST['phone'];
  $email = $_POST['email'];


  $h = curl_init();
  curl_setopt($h, CURLOPT_URL, "//remote JSP page"); 
  curl_setopt($h, CURLOPT_HEADER, true);
   curl_setopt($h, CURLOPT_POST, true);
  curl_setopt($h, CURLOPT_POSTFIELDS, array(

  'fname' => '$fname',
  'address' => '$address',
  'city' => '$city',
  'state' => '$state',
  'zip' => '$zip',
  'phone' => '$phone',
  'email' => '$email',
  ));
  curl_setopt($h, CURLOPT_RETURNTRANSFER, 1);

  $result = curl_exec($h);
  echo $result;


      }
  ?>

I have an HTML form, being submitted to a PHP page. The PHP page needs to validate a captcha and then pass the form values to a JSP page. I have NO control over the JSP page. Captcha is working beautifully. Something is getting lost in my PHP page, as when it loads the information on the JSP page, the CSS and headers of the target page aren't loading and the form data isn't being passed. I do not have access to the JSP page. Any ideas?

BTW, Captcha validation is working fine and the HTML works fine if I pass it directly to the JSP page:

 <?php
  require_once('recaptchalib.php');
  $privatekey = "privatekeyhere";
  $resp = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);

  if (!$resp->is_valid) {
    // What happens when the CAPTCHA was entered incorrectly
    die ("<p align='center'>The reCAPTCHA wasn't entered correctly. Please go back and try it again." .
         "(reCAPTCHA said: " . $resp->error . ")</p>");
  } else {


  $ipaddress = $_SERVER["REMOTE_ADDR"];
  $fname = $_POST['fname'];
  $address = $_POST['address'];
  $city = $_POST['city'];
  $state = $_POST['state'];
  $zip = $_POST['zip'];
  $phone = $_POST['phone'];
  $email = $_POST['email'];


  $h = curl_init();
  curl_setopt($h, CURLOPT_URL, "//remote JSP page"); 
  curl_setopt($h, CURLOPT_HEADER, true);
   curl_setopt($h, CURLOPT_POST, true);
  curl_setopt($h, CURLOPT_POSTFIELDS, array(

  'fname' => '$fname',
  'address' => '$address',
  'city' => '$city',
  'state' => '$state',
  'zip' => '$zip',
  'phone' => '$phone',
  'email' => '$email',
  ));
  curl_setopt($h, CURLOPT_RETURNTRANSFER, 1);

  $result = curl_exec($h);
  echo $result;


      }
  ?>

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

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

发布评论

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

评论(1

飘落散花 2024-12-14 16:50:40

我可以立即发现的问题:

  1. CURLOPT_POSTFIELD 必须是 POST 字符串,而不是数组。
  2. 即便如此,您还是要发布表示变量名称的字符串(您应该发布值。

对于第 1 点,这里有一个由 David Walsh 编写的简单 cUrl 教程,涵盖了与您的情况非常相似的情况,并包含一种在 POST 字符串中转换数组的方法: http://davidwalsh.name/execute-http-post-php-curl

对于点2、'singlequotes' 内的字符串不会被计算。要引用变量,您应该使用 $var,而不是 '$var'。 奖励:

POST/GET 字符串中的任何内容都应该进行 urlencode 编码。

Problems I can spot right away:

  1. CURLOPT_POSTFIELD has to be a POST string, not an array.
  2. Even then, you're posting strings representing variable names (you should post the value instead.

For point 1, here's a simple cUrl tutorial by David Walsh, covering a case very similar to yours and containing a way to transform arrays in POST strings: http://davidwalsh.name/execute-http-post-php-curl

For point 2, strings inside 'single quotes' are not evaluated. To refer to a variable, you should use $var, not '$var'.

Bonus: anything in a POST/GET string should be urlencoded.

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