您的位置:首页 > 理论基础 > 计算机网络

android http请求 状态消息返回

2012-11-27 17:30 281 查看
发送http请求 得到网络请求返回状态消息:

方法如下:

public int getRespStatus(String url) {

int status = -1;

try {

HttpHead head = new HttpHead(url);

HttpClient client = new DefaultHttpClient();

HttpResponse resp = client.execute(head);

status = resp.getStatusLine().getStatusCode();

} catch (IOException e) {

}

if (DEBUG) {

Log.v(TAG, "status=" + status);

}

return status;

}

status 返回值是404, 500, 502, 504等http状态消息
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: