使用java獲取手機號歸屬地等信息httpClient實現

java獲取手機號歸屬地

一般想獲取手機號歸屬地等信息個人是無法獲取的,但是可以通過調用第三方接口獲取,具體百度搜索很多

這裡例子提供一個淘寶的接口 ,該功能已經發布到網站作為一個在線小工具,

拿走不謝:

http://www.yzcopen.com/con/iphone

用都的jar httpClient相關

代碼:


<code>

public

class

HttpTool

{

private

final

static

String iphoneurl =

"http://mobsec-dianhua.baidu.com/dianhua_api/open/location?tel="

;

public

static

String doHttpgetAPi(String url) throws

Exception

{ HttpGet post =

null

; CloseableHttpResponse response =

null

;

try

{ CloseableHttpClient httpClient = HttpClients.createDefault(); post =

new

HttpGet(url); post.setHeader(

"Content-Type"

,

"application/json; charset=utf-8"

); post.setHeader(

"Connection"

,

"Close"

); response = httpClient.execute(post);

if

(response !=

null

){ HttpEntity entity=response.getEntity(); String str=EntityUtils.toString(entity);

return

str; }

return

null

; }

catch

(

Exception

e) { e.printStackTrace(); }

finally

{

if

(response!=

null

){ response.getEntity().getContent().close(); }

if

(post !=

null

){

try

{ post.releaseConnection(); }

catch

(

Exception

e) { e.printStackTrace(); } } }

return

null

; }

public

static

void main(String[] args) { String ipurl = iphoneurl+

"您的手機號"

; String result = HttpTool.doHttpgetAPi(url); System.out.println(result ); } }/<code>

<code>{行返回的結果是:{

"response"

:{

"13854510856"

:{

"detail"

:{

"area"

:[{

"city"

:

"煙臺"

}],

"province"

:

"山東"

,

"type"

:

"domestic"

,

"operator"

:

"移動"

},

"location"

:

"山東煙臺移動"

}},

"responseHeader"

:{

"status"

:200,

"time"

:1579079131507,

"version"

:

"1.1.0"

}}/<code>


分享到:


相關文章: