import com.baidubce.http.ApiExplorerClient; import com.baidubce.http.AppSigner; import com.baidubce.http.HttpMethodName; import com.baidubce.model.ApiExplorerRequest; import com.baidubce.model.ApiExplorerResponse; // 全球ip归属地查询 Java示例代码 public class RequestDemo { public static void main(String[] args) { String path = "http://gwgp-ky3hr3o7gyd.n.bdcloudapi.com/20-1"; ApiExplorerRequest request = new ApiExplorerRequest(HttpMethodName.POST, path); request.setCredentials("您的 access key", "您的 secret key"); request.addHeaderParameter("Content-Type", "application/json;charset=UTF-8"); request.addQueryParameter("ip", ""); ApiExplorerClient client = new ApiExplorerClient(new AppSigner()); try { ApiExplorerResponse response = client.sendRequest(request); // 返回结果格式为Json字符串 System.out.println(response.getResult()); } catch (Exception e) { e.printStackTrace(); } } }
点击复制代码
{
"showapi_res_error": "",
"showapi_res_code": 0,
"showapi_res_id": "970e10a1e51b493bb0ef0c0a07e79007",
"showapi_res_body": {
"region": "广东",//省级
"isp": "电信",//运营商
"en_name": "China",
"ip": "116.4.201.181",
"country": "中国",//国家
"city": "东莞",//市级
"ret_code": 0,
"county": "",//县级
"continents": "亚洲",
"city_code": "441900",
"lnt": "113.760234",//经度
"en_name_short": "CN",
"lat": "23.048884"//纬度
}
}
{
"showapi_res_error": "",
"showapi_res_code": 0,
"showapi_res_id": "efb14ccc2ce444afaf953d83d71c2703",
"showapi_res_body": {
"ret_code": -1,
"remark": "ip格式不正确!",
"ip": "116.4.20"
}
}