import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class HttpClientExample {
public static void main(String[] args) {
try {
String url = "https://mooping-openapi.thaidata.cloud/v1.1/sms-simple";
URL obj = new URL(url);
HttpURLConnection connection = (HttpURLConnection) obj.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("accept", "*/*");
connection.setRequestProperty("access-key-token", "Access Key Token");
connection.setRequestProperty("access-key-id", "Access Key Id");
connection.setRequestProperty("Content-Type", "application/json");
connection.setDoOutput(true);
connection.setDoInput(true);
String jsonData = "{" +
"phoneCode": "Client Phone Country Code"," +
"phoneNumber": "Client Phone Number"," +
"senderId": "Your Activate SenderId"," +
"message": "Message Content"" +
"}";
try (DataOutputStream wr = new DataOutputStream(connection.getOutputStream())) {
wr.writeBytes(jsonData);
wr.flush();
}
int responseCode = connection.getResponseCode();
System.out.println("Response Code: " + responseCode);
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuilder response = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.println("Response Body: " + response.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}
const axios = require('axios');
const url = 'https://mooping-openapi.thaidata.cloud/v1.1/sms-simple';
const headers = {
'accept': '*/*',
'access-key-token': 'Access Key Token',
'access-key-id': 'Access Key Id',
'Content-Type': 'application/json'
};
const data = {
"phoneCode": "Client Phone Country Code",
"phoneNumber": "Client Phone Number",
"senderId": "Your Activate SenderId",
"message": "Message Content"
};
axios.post(url, data, { headers })
.then(response => {
console.log("Response Code:" , response.status);
console.log("Response Body:", response.data);
})
.catch(error => {
console.error(error);
});
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
string url = "https://mooping-openapi.thaidata.cloud/v1.1/sms-simple";
var headers = new System.Net.Http.Headers.HttpRequestHeaders();
headers.Add("accept", "*/*");
headers.Add("access-key-token", "Access Key Token");
headers.Add("access-key-id", "Access Key Id");
headers.Add("Content-Type", "application/json");
var data = new
{
phoneCode = "Client Phone Country Code",
phoneNumber = "Client Phone Number",
senderId = "Your Activate SenderId",
message = "Message Content"
};
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Clear();
client.DefaultRequestHeaders.AddHeaders(headers);
var jsonContent = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PostAsync(url, jsonContent);
Console.WriteLine($"Response Code: {(int)response.StatusCode} {response.ReasonPhrase}");
if (response.IsSuccessStatusCode)
{
string responseContent = await response.Content.ReadAsStringAsync();
Console.WriteLine("Response Body:");
Console.WriteLine(responseContent);
}
else
{
Console.WriteLine("Request failed.");
}
}
}
}
package main
import (
"bytes"
"fmt"
"net/http"
"encoding/json"
)
func main() {
url := "https://mooping-openapi.thaidata.cloud/v1.1/sms-simple"
headers := map[string]string{
"accept": "*/*",
"access-key-token": "Access Key Token",
"access-key-id": "Access Key Id",
"Content-Type": "application/json",
}
data := map[string]interface{}{
"phoneCode": "Client Phone Country Code",
"phoneNumber": "Client Phone Number",
"senderId": "Your Activate SenderId",
"message": "Message Content",
}
jsonData, err := json.Marshal(data)
if err != nil {
fmt.Println("Error marshaling JSON data:", err)
return
}
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
if err != nil {
fmt.Println("Error creating request:", err)
return
}
for key, value := range headers {
req.Header.Set(key, value)
}
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println("Error sending request:", err)
return
}
defer resp.Body.Close()
fmt.Printf("Response Code: %d %s", resp.StatusCode, resp.Status)
if resp.StatusCode == http.StatusOK {
responseBody := new(bytes.Buffer)
responseBody.ReadFrom(resp.Body)
fmt.Println("Response Body:", responseBody.String())
} else {
fmt.Println("Request failed.")
}
}