【问题标题】:pass data to request method of HttpSocket in CakePHP将数据传递给 CakePHP 中 HttpSocket 的请求方法
【发布时间】:2012-04-25 19:06:53
【问题描述】:

我正在使用 CakePHP 的 HttpSocket request 方法来执行对某些 api 的一些请求。我想随我的请求发送一些参数。有人知道我如何使用该方法发送一些参数吗?例如,假设我正在向这个 url 发送请求:

http://www.mydomain.com

但我想向这个请求发送参数,例如:

username: smith123
password: qwerty

如果我用 Ajax 来做这件事,我会做这样的事情:

$.post('http://www.mydomain.com', {username: "smith123", password: "qwerty"}, 'json');

如何使用 CakePHP 的 HttpSocket 类的请求方法将这些参数(也是上面 ajax 示例中指定的预期数据类型)发送到 http://www.mydomain.com

请帮忙

谢谢

【问题讨论】:

    标签: php cakephp cakephp-1.3


    【解决方案1】:

    我认为你会想要使用 get 或 post 方法,而不是 request,这是基本方法。 http://book.cakephp.org/1.3/en/view/1518/get

    您可以在 get 方法的第二个参数中将参数作为字符串或数组传递:

    App::import('Core', 'HttpSocket');
    $HttpSocket = new HttpSocket();
    $results = $HttpSocket->get('http://www.google.com/search', 'q=cakephp');
    debug($HttpSocket->response);
    

    【讨论】:

      猜你喜欢
      • 2015-11-24
      • 2016-03-28
      • 1970-01-01
      • 2020-02-14
      • 2020-01-25
      • 1970-01-01
      • 2013-02-20
      • 1970-01-01
      相关资源
      最近更新 更多