如何对Stanford NLP进行PHP curl调用?

问题描述 投票:0回答:1

通过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的格式,但是尝试使用数组的其他变体后仍然没有运气。

php curl stanford-nlp
1个回答
0
投票

您需要告诉curl进行定期发布。只需在CURLOPT_POSTFIELDS分配之前添加以下行:

curl_setopt($ch, CURLOPT_POST, true);
© www.soinside.com 2019 - 2024. All rights reserved.