Skip to content

Commit 1e1a32c

Browse files
committed
Fix Java code example
1 parent 7d82238 commit 1e1a32c

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

web/pages/index.vue

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -385,28 +385,26 @@ client.Messages.Send(context.Background(), &httpsms.MessageSendParams{
385385
<v-tab-item value="java">
386386
<pre v-highlight class="java w-full mt-n2 mb-n13">
387387
<code>var client = HttpClient.newHttpClient();
388-
389388
var apiKey = "Get API Key from https://httpsms.com/settings";
390389

391-
JSONObject request = new JSONObject();
392-
request.put("content", "This is a sample text message");
393-
request.put("from", "+18005550199")
394-
request.put("to", "+18005550100")
390+
var payload = """
391+
{
392+
"content": "This is a sample text message",
393+
"from": "+18005550199",
394+
"to": "+18005550100"
395+
}
396+
""";
395397

396-
// create a request
397398
var request = HttpRequest.newBuilder()
398-
.uri(URI.create("https://api.httpsms.com/v1/messages/send"))
399-
.header("accept", "application/json")
400-
.header("x-api-key", apiKey)
401-
.setEntity(new StringEntity(request.toString()))
402-
.POST()
403-
.build();
404-
405-
// use the client to send the request
406-
var response = client.send(request, new JsonBodyHandler&#60;&#62;(APOD.class));
399+
.uri(URI.create("https://api.httpsms.com/v1/messages/send"))
400+
.header("accept", "application/json")
401+
.header("Content-Type", "application/json")
402+
.header("x-api-key", apiKey)
403+
.POST(HttpRequest.BodyPublishers.ofString(payload))
404+
.build();
407405

408-
// the response:
409-
System.out.println(response.body().get());
406+
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
407+
System.out.println(response.body());
410408
</code>
411409
</pre>
412410
</v-tab-item>

0 commit comments

Comments
 (0)