일부 로그를 데이터베이스로 보내는 프로그램을 개발 중입니다. 로그로서 주요 아이디어는 최대한 많은 정보를 저장하는 것입니다. 로그를 저장하는 서버가 다운 된 경우이를 피하고 싶습니다. 내가 뭘 하려는지 http 요청을하고 완전히 서버 응답을 무시하는 것입니다, 그건 중요하지 않아 온라인 또는 오프라인입니다. 지금까지 내가 한 일은 나의 요청에 타임 아웃을 설정하는 것이지만 그건 내 문제를 해결하지 못한다. 여기 내 코드는 다음과 같습니다.Android에서 http 요청을하고 응답을 무시합니다.
public synchronized void LOG_sendERROR(String token, String channelnumber, String type)
{
HttpResponse response = null;
HttpParams httpParameters = new BasicHttpParams();
int timeout = 3000;
HttpConnectionParams.setConnectionTimeout(httpParameters,timeout);
int timeoutsocket = 5000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutsocket);
DefaultHttpClient httpclient = new DefaultHttpClient(httpParameters);
try
{
if (ep.getString("username", "").length() == 0)
return ;
String url = Server.Log_Server + "/LOG_CHANNEL_LOGS.aspx?params=1";
log.i("LOGS", url);
HttpGet c = new HttpGet(url);
response = httpclient.execute(c);
return ;
}
catch (Exception e)
{
e.printStackTrace();
try
{
if (response != null)
response.getEntity().consumeContent();
}
catch (Exception f)
{
}
return ;
}
}
서버가 다운 된 경우 3 초 동안 멈 춥니 다. 로그를 보내려고합니다. 클라이언트 응용 프로그램이 클라이언트가 보낸 로그를 서버가 저장했는지 여부를 알 필요가 없습니다. http 요청을하고 응답을 무시하려면 어떻게해야합니까?
Asynctask를 사용해보세요 ... –