Back to LanguageTool Homepage - Privacy - Imprint

How to send "data" parameter for language check


(kumuda) #1

Hi,
I am running language tool on localhost,
I used to deal with only text in the beginning and this CURL PoST method would work just fine:

function post_request($text, $language_code, $ignored_rules) {
$data = “text=$text&language=$language_code&disabledRules=$ignored_rules”;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, “http://localhost:8082/v2/check”);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(‘Content-Type: application/x-www-form-urlencoded’));
//curl_setopt($ch, CURLOPT_HTTPHEADER, array(‘Accept: application/json’));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
dpm($result);
if(!curl_errno($ch)){
$data = json_decode($result);
}
return $data;
}
But I am dealing eith HTML now and I have created a json object separating markup from text.
Eg : {“annotation”:[ {“text”: "A "}, {“markup”: “<b>”}, {“text”: “test”}, {“markup”: “</b>”} ]}

I am unable to send the post request succesfully.
Every time it gives me an error saying Internal Error: null
Can you help me please?


(Daniel Naber) #2

You need to use a recent snaphot, e.g. https://languagetool.org/download/snapshots/LanguageTool-20180925-snapshot.zip


(Ruud Baars) #3

For interpreting the results, json to array might help.
By the way, I am using this continuously; You could re-use my code. If interested, contact me at info at taaltik dot nl