如何使用drupal_http_request构建https POST请求?

BLV*_*BLV 3 https http-headers drupal-7

我想向https服务器发送POST请求.

$data = 'name=value&name1=value1';

$options = array(
  'method' => 'POST',
  'data' => $data,
  'timeout' => 15,
  'headers' => array('Content-Type' => 'application/x-www-form-urlencoded'),
);

$result = drupal_http_request('http://somewhere.com', $options);
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚在上面的POST示例代码中实现https选项.

有人可以解释一下如何做到这一点吗?我对使用Drupal的PHP编码很新,我绝对可以使用该指南.

我发现所有需要的是在协议中设置它.所以我得到了这段代码.

$data = 'access_token=455754hhnaI&href=fb&template=You have people waiting to play with you, play now!';

$options = array(
  'method' => 'POST',
  'data' => $data,
  'timeout' => 15,
  'headers' => array('Content-Type' => 'application/x-www-form-urlencoded'),
);

$result = drupal_http_request('https://graph.facebook.com/1000721/notifications?', $options);
Run Code Online (Sandbox Code Playgroud)

它仍然无法正常工作.如果我通过Firefox发布https://graph.facebook.com/1000080521/notifications?access_token=45575FpHfhnaI&href=fb&template=You have people waiting to play with you, play now!它的工作原理.

我可能没有在Drupal中正确构建请求.

我究竟做错了什么?如何让我的代码工作?

kia*_*uno 8

使用drupal_http_request()安全连接(https://)或没有安全连接(http://)之间没有区别.

必须编译PHP以支持OpenSSL; 否则,drupal_http_request()不支持安全连接.除此之外,唯一的问题可能是代理服务器不支持安全连接.

另请注意,您使用的https://graph.facebook.com/1000721/notifications?是请求的URL.问号不应该是URL的一部分.

我还会使用drupal_http_build_query()来构建用于请求的数据.

$data = array(
  'access_token' => '455754hhnaI',
  'href' => 'fb',
  'template' => 'You have people waiting to play with you, play now!'
);

$options = array(
  'method' => 'POST',
  'data' => drupal_http_build_query($data),
  'timeout' => 15,
  'headers' => array('Content-Type' => 'application/x-www-form-urlencoded'),
);

$result = drupal_http_request('https://graph.facebook.com/1000721/notifications', $options);
Run Code Online (Sandbox Code Playgroud)