卷曲跟随位置而不是重定向到外部站点

时间:2015-10-31 18:36:27

标签: php curl

我有一个初始页面,其中包含一个html表单,该表单将数据传输到post.php然后将其卷曲。

问题: 我正在将数据传输到URL,但是当您从html页面单击提交时,url结构会将您带到以下http://localhost:8888/post.php并将所有html返回并将其放在post.php中。

但是,我希望它跟随外部URL,但我回来的是一个包含相对URL的标题响应。我试过CURLOPT_FOLLOWLOCATION但仍然没有。

HTML

 <form name="nonjava" method="post" action="/post.php">
    <input name="postdata" id="nonjavapostdata" type="hidden" value="<?php echo $variables['postdata']; ?>" />
    <label for="amount1" class="">£</label>
    <input required="" type="text" class="" id="amount1" name="amount1">

    <input required="" type="text" class="" id="amount2" name="amount2">
    <label for="amount2" class="">P</label>

    <button type="submit" class="btn btn-default" href="">Submit</button>
</form>

现在有了这些数据,我将所有内容转移到post.php并确定所有$_POST并将其作为HTTP标头卷曲到外部网址。

PHP

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'postdata=' . urlencode(xmlTransfer()));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');

// curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
// curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// curl_setopt($ch, CURLOPT_VERBOSE, true);

// Download the given URL, and return output
$output = curl_exec($ch);

// Close the cURL resource, and free system resources
curl_close($ch);

0 个答案:

没有答案