以弹簧控制器方法

时间:2018-04-03 07:45:27

标签: java php spring

我有这个控制器功能

@ResponseBody
@RequestMapping(value = { "/send_now" }, method = RequestMethod.GET)
public void send_now()throws ClientProtocolException, IOException {
CloseableHttpClient client = HttpClients.createDefault();
//HttpPost httpPost = new HttpPost("http://localhost/batch_insert/sender.php");
HttpPost httpPost = new HttpPost("https://hookb.in/vaPG2gkm");

List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("sender", "TRADER"));
params.add(new BasicNameValuePair("phone", "4463839399393"));
httpPost.setEntity(new UrlEncodedFormEntity(params));

CloseableHttpResponse response = client.execute(httpPost);
client.close();
}

我正在尝试发帖并在此处查看结果https://hookbin.com/bin/vaPG2gkm

最终,我希望能够在php脚本中捕获发布的数据

error_reporting(E_ALL & ~E_NOTICE);
require ('config.php');
require ('db_class.php');
$db = new MySQLDatabase;


$post = file_get_contents('php://input');


$msg = rand(30,100);


$data = file_get_contents('php://input');
$phone = $data['phone'];
$sender = $data['sender'];

$msg = 'This was sent via the Api';
$time = date('Y-m-d H:i:s');

$sql="insert into clickatellout (sender,receiver,msg,msgtype,status,flag,scheduledtime) 
                              values ('".$sender."','".$phone."','".$msg."','SMS:TEXT','Send','1','".$time."')";
$db->query($sql);
echo 'ok';

当我运行方法send_now时,没有发布数据,我在控制台中收到此警告

  

警告:无法评估类型[void]的Jackson序列化:   java.lang.IllegalStateException:无法实例化标准   序列化器(类型   com.fasterxml.jackson.databind.ser.std.NullSerializer):类   com.fasterxml.jackson.databind.ser.BasicSerializerFactory不能   访问一个类的成员   带修饰符的com.fasterxml.jackson.databind.ser.std.NullSerializer   “私有”

为什么功能不发布数据?。

1 个答案:

答案 0 :(得分:2)

看来你的send_now方法正在返回,杰克逊试图序列化。要解决此问题,您可以尝试返回某些内容或将以下注释添加到方法中:

@ResponseStatus(value = HttpStatus.OK)