php - 将数据从 Drupal 发送到 node.js

标签 php node.js drupal drupal-7 drupal-form-submission

我是 drupal 的新手。

我试图将数据从drupal发送到node.js函数并将数据从node保存到mongo中。

我用php写了一个函数

function sample_working_submit($form, &$form_state) { //Function to connect with node and save into Mongo using node
  $Name = check_plain($form_state['values']['Name']);
  $Age = check_plain($form_state['values']['Age']);
  $request_url = "http://10.20.5.112:3001/save/$Name/$Age ";
  $response = drupal_http_request($request_url);
}

只要名称(输入)之间没有“空格”,这就可以工作。如何保存带有空格的输入。为什么会出现这个问题?

如何将函数重写为 post?

最佳答案

<?php
$url = http://localhost:8080/myservlet;

$data = array (
    'name' => check_plain($form_state['values']['Name']),
    'age' => check_plain($form_state['values']['Age'])
    );

$response = drupal_http_request($url, $headers, 'POST', json_encode($data));
?>

这会将数据 POST 到 URL。请注意,您还需要更改服务器端的逻辑以接收 POST 数据而不是 GET 数据。

Refer here了解更多信息

关于php - 将数据从 Drupal 发送到 node.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16895916/

相关文章:

PHP构建系统

javascript - Node.js 在 cmd 中运行,但不在浏览器中运行

node.js - Postgres 尝试返回我的模型中不存在的列

node.js - 如何安装socket.io

php - 异常 : Cannot redeclare function in web. php,但它是此函数的唯一出现

php - Laravel 5.7 中的 Arr::get() 与 data_get()

php - 重写数据库值php

php - jquery向多个选择下拉列表添加属性

mysql - 在 Drupal 7 结构化查询中使用 AS 语法

Drupal Rules 一次性登录地址