https - 如何使用 drupal_http_request 构造 https POST 请求?

标签 https drupal-7 http-headers

我想向 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);

我不知道在上面的 POST 示例代码中实现 https 选项。

谁能解释一下如何做到这一点?我对使用 Drupal 进行 PHP 编码非常陌生,我绝对可以使用该指南。

我发现只需在协议(protocol)中设置它。所以我得到了这段代码。

$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);

还是不行。如果我通过 Firefox 使用 https://graph.facebook.com/1000080521/notifications?access_token=45575FpHfhnaI&href=fb&template=有人等着和你一起玩,现在就玩吧! 它有效。

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

我做错了什么?如何让我的代码正常工作?

最佳答案

使用 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);

关于https - 如何使用 drupal_http_request 构造 https POST 请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13916287/

相关文章:

jquery - 在 http 页面上使用 https 的 Ajax

Drupal token 当前页面 :query

git - 将大型提交推送到 GitHub 会导致致命写入错误 : Bad file descriptor

encryption - 未加密的 SSL 协议(protocol)?

javax.net.ssl.SSLHandshakeException : Received fatal alert: handshake_failure java 1. 7_45

php - 用于访问 Drupal 7 中数据字段的简单 mysql 查询

php - 如何让 PagerDefault 查询与 Drupal 7 一起正常工作?

ruby-on-rails - 使用 HTTParty 解析 HTTP header 'set-cookie'

ios - 在 iOS 上使用带有 NSMutableURLRequest 的接受 header

html - BaseHTTPRequestHandler 卡在 self.rfile.read()