如何使用drupal_http_request构建https POST请求? [英] how to construct an https POST request with drupal_http_request?
问题描述
我想向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选项。 p>
任何人都可以解释一下我该怎么做?我非常新的使用Drupal的PHP编码,我一定可以使用指导。
我发现所有需要的是在协议中设置它。所以我得到这个代码。
$ data ='access_token = 455754hhnaI& href = fb&模板=你有人等着和你一起玩,现在玩吧!
$ 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=你有人等待和你一起玩,现在玩吧! code>它工作。
我可能不会在Drupal中正确构建请求。
我做错了什么?如何使我的代码工作?
使用 drupal_http_request() / code>安全连接(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'=>'你有人等待和你一起玩,现在玩!'
);
$ 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);
I want to send a POST request to an https server.
$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);
I can't figure out out to implement the https options in the POST example code above.
Can anyone please explain me how to do this? I am quite new to PHP coding with Drupal, and I could definitely use the guidance.
I found that all is needed is to set it in the protocol. So I got to this code.
$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);
It still doesn't work. If I post via Firefox with https://graph.facebook.com/1000080521/notifications?access_token=45575FpHfhnaI&href=fb&template=You have people waiting to play with you, play now!
it works.
I am probably not constructing the request properly in Drupal.
What am I doing wrong? How can I get my code to work?
There is no difference between using drupal_http_request()
with a secure connection (https://), or without a secure connection (http://).
PHP must be compiled with support for OpenSSL; otherwise, drupal_http_request()
doesn't support secure connections. Apart that, the only issue could be the proxy server not supporting a secure connection.
As side note, you are using https://graph.facebook.com/1000721/notifications?
as URL for the request. The question mark should not be part of the URL.
I would also use drupal_http_build_query() to build the data to use for the request.
$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);
这篇关于如何使用drupal_http_request构建https POST请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!