這是Rapid API為我創建的代碼。
HttpRequest request = HttpRequest.newBuilder()
.URI(URI.create("https://dnaber-languagetool.p.rapidapi.com/v2/check")
.header("content-type", "application/x-www-form-urlencoded")
.header("x-rapidapi-host", "dnaber-languageagetool.p.rapidapi.com")
.header("x-rapidapi-key", "[redacted to prevent abuse]")
.method("POST", HttpRequest.BodyPublishers.ofString("text=This is a error.& language=en-US")
.build()。
HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString())。
System.out.println(response.body())。
這是它的輸出結果:
這是它的輸出結果。
{"software":{"name": "LanguageTool","版本":"5. 5-SNAPSHOT"/span>,"buildDate"/span>:"2021-09-17 18:41: 41 0000","apiVersion":1," premium"。 false,"premiumHint":"你可能缺少只有高級版本才能發現的錯誤。請通過support<at>languagetoolplus.com聯系我們。 ","status":""}," warnings":{"incompleteResults": false},"language":{"name":"English (US)","code"。 "en-US"," detectedLanguage":{"name": "English (US)","code":"en-US", " confidence":0. 528}},"matches":[{"message":"如果下面的詞以元音開頭,就用 "an "代替 "a",例如,"an article","an hour"。 ","shortMessage":"錯誤的文章","替換"。 [{"value":"an"}], "offset": 8,"length":1, "context": {"text":"this is a error. ","offset":8,"length": 1},"句子":"這是一個錯誤。 ","type":{"typeName":"Other"},"rules": 'an'","issueType":"拼寫錯誤","類別": {"id":"MISC","name": "Miscellaneous"}},"ignoreForIncompleteSentence"。 false,"contextForSureMatch":1}]}。
它似乎在作業,但我如何使它檢查我的字串而不是他們給我的字串?
例如,如果我有String myString = "Hello World. 你好,世界。我想檢查這個,我應該把這個字串放在他們提供給我的代碼中的什么地方?
我試著做了.method(myString),但它沒有起作用。
謝謝你的幫助。
uj5u.com熱心網友回復:
你需要看一下API檔案,但似乎你需要更新請求體
我不太熟悉API,但我想知道你是否需要更新請求體。
我對這個http客戶端類并不熟悉,但無論是在方法上
String x = "這是一個錯誤。" /span>;
...
.method("POST", HttpRequest.BodyPublishers.ofString("text=" URLEncoder.encode(x, StandardCharsets.UTF_8.toString() ) "&language=en-US")
.build()。
或者需要給HttpResponse.BodyHandlers.ofString()/code>一些類似的輸入
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/324457.html
標籤:
