Hello, I tried to translate the following working code:
To:
But I get everytime an error - without an ErrorMessage.... I dont see the mistake...
Java:
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\n\t\n \"text\": [\n \"Hello, world!\"\n ],\n \"target_lang\": \"DE\"\n\n}");
Request request = new Request.Builder()
.url("https://api-free.deepl.com/v2/translate")
.method("POST", body)
.addHeader("Authorization", "DeepL-Auth-Key myKey")
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();
To:
B4X:
Dim j As HttpJob
j.Initialize("", Me)
Dim poststr As String = "https://api-free.deepl.com/v2/translate"
Dim jsonString As String = ""
jsonString = "{'text': ["
jsonString = jsonString & "Hello, world!"
jsonString = jsonString & "]"
jsonString = jsonString & ",'target_lang': 'DE'}"
j.PostString(poststr, jsonString)
j.GetRequest.SetHeader("Authorization", "DeepL-Auth-Key myKey")
j.GetRequest.SetHeader("Content-Type", "application/json")
Wait For (j) JobDone(j As HttpJob)
If j.Success = True Then
Log(j.GetString)
Else
Log(j.ErrorMessage)
End If
j.Release
But I get everytime an error - without an ErrorMessage.... I dont see the mistake...