我正在使用PHP的函数file_get_contents()来获取URL的内容,然后我通过变量处理标头$http_response_header.
现在问题是某些URL需要将一些数据发布到URL(例如,登录页面).
我怎么做?
我意识到使用stream_context我可以做到这一点,但我并不完全清楚.
谢谢.
我试图找到一种无需cURL的方法,通过http web请求将数据发送到第三方支付网关.我开发了以下代码,实际上它与接收页面成功通信,但显然POST数据没有被发送.
<?php
function makeWebRequest()
{
//URL where to send the data via POST
$url = 'http://localhost/connect_to_gateway/receive.php';
//the actual data
$xml = '<?xml version="1.0" encoding="UTF-8"?>' .
'<test>' .
'Hi there!' .
'</test>';
$data = array('xml' => $xml);
//prepare the HTTP Headers
$content_type = 'text/xml';
$data = http_build_query($data);
// use key 'http' even if you send the request to https://...
$options = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: ' . addslashes($content_type) .'\r\n'
. 'Content-Length: ' . strlen($data) …Run Code Online (Sandbox Code Playgroud)