import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
public class test
{
public static void main(String args[])
{
String url = "https://api.ihuyi.com/empty-number/submit";
Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json; charset=utf-8");
headers.put("Date", "Tue, 26 Aug 2025 07:14:23 GMT"); // 請?zhí)鎿Q為當前的GMT時間,可參考:https://gitee.com/shsurlink/api-demo/blob/master/hmac-auth/java/src/main/java/com/ihuyi/Main.java
headers.put("Authorization", "Signature xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); // 請?zhí)鎿Q為您的鑒權(quán)簽名,可參考:https://gitee.com/shsurlink/api-demo/blob/master/hmac-auth/java/src/main/java/com/ihuyi/Main.java
String jsonString = "{\"mobiles\":[\"18800000000\",\"18800000001\"]}";
try {
// 確保jsonString不為空再發(fā)送請求
if (jsonString != null) {
Map<String, Object> response = sendRequest(url, headers, jsonString, "POST");
// 打印響應
System.out.printf("狀態(tài)碼: %s%n", response.get("status"));
System.out.printf("響應內(nèi)容: %s%n", response.get("body"));
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static Map<String, Object> sendRequest(String url, Map<String, String> headers, String requestBody, String method) throws Exception {
HttpRequest.Builder requestBuilder = HttpRequest.newBuilder()
.uri(URI.create(url))
.method(method, requestBody.isEmpty() ?
HttpRequest.BodyPublishers.noBody() :
HttpRequest.BodyPublishers.ofString(requestBody, StandardCharsets.UTF_8));
headers.forEach(requestBuilder::header);
HttpClient httpClient = HttpClient.newBuilder().build();
HttpResponse<String> response = httpClient.send(
requestBuilder.build(),
HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8)
);
Map<String, Object> result = new HashMap<>();
result.put("status", response.statusCode());
result.put("body", response.body());
return result;
}
}
國內(nèi)專業(yè)互聯(lián)網(wǎng)團隊
21年行業(yè)經(jīng)驗
7x24小時售后支持
豐富的行業(yè)經(jīng)驗
Copyright ? 2004-2025 上海思銳信息技術(shù)有限公司 All rights reserved. 滬ICP備07035915號-15 電信增值業(yè)務許可證:B2-20160082
服務熱線:
4008 808 898
服務熱線(工作時間):
4008 808 898
業(yè)務咨詢(非工作時間):
售后咨詢(非工作時間):