通过curl调用使用斯坦福NLP本地服务器
curl --data "this is a test" http://localhost:9001/?properties={%22prettyPrint%22%3A%22true%22}
并且一切正常。当我尝试在PHP中使用等效的curl命令作为
$ch = curl_init('http://localhost:9001/?properties={%22prettyPrint%22%3A%22true%22}');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'this is a test');
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);
我得到一个错误
string(49) "<h1>400 Bad Request</h1>URISyntaxException thrown"
我认为问题是POSTFIELDS
的格式,但是尝试使用数组的其他变体后仍然没有运气。
您需要告诉curl进行定期发布。只需在CURLOPT_POSTFIELDS分配之前添加以下行:
curl_setopt($ch, CURLOPT_POST, true);