-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathspell_check.js
50 lines (42 loc) · 1.48 KB
/
spell_check.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'use strict';
let https = require ('https');
let host = 'api.cognitive.microsoft.com';
let path = '/bing/v7.0/spellcheck';
/* NOTE: Replace this example key with a valid subscription key (see the Prequisites section above). Also note v5 and v7 require separate subscription keys. */
let key = 'd879dd6c86654708affebe35c713972b';
// These values are used for optional headers (see below).
// let CLIENT_ID = "<Client ID from Previous Response Goes Here>";
// let CLIENT_IP = "999.999.999.999";
// let CLIENT_LOCATION = "+90.0000000000000;long: 00.0000000000000;re:100.000000000000";
let mkt = "en-US";
let mode = "proof";
let text = "Hollo, wrld!";
let query_string = "?mkt=" + mkt + "&mode=" + mode;
let request_params = {
method : 'POST',
hostname : host,
path : path + query_string,
headers : {
'Content-Type' : 'application/x-www-form-urlencoded',
'Content-Length' : text.length + 5,
'Ocp-Apim-Subscription-Key' : key,
// 'X-Search-Location' : CLIENT_LOCATION,
// 'X-MSEdge-ClientID' : CLIENT_ID,
// 'X-MSEdge-ClientIP' : CLIENT_ID,
}
};
let response_handler = function (response) {
let body = '';
response.on ('data', function (d) {
body += d;
});
response.on ('end', function () {
console.log (body);
});
response.on ('error', function (e) {
console.log ('Error: ' + e.message);
});
};
let req = https.request (request_params, response_handler);
req.write ("text=" + text);
req.end ();