gpt4 book ai didi

android - 上传或下载经纬度到服务器的最快方法

转载 作者:行者123 更新时间:2023-11-29 20:47:48 25 4
gpt4 key购买 nike

我需要上传和下载 3 个字段,其中包含纬度、经度以及通过电子邮件过滤的 mysql-php 中最后看到的字段。 Android 中执行此操作最快且内存消耗更少的方法是什么?

在后台尝试过异步,但需要大约 10 秒才能返回。

公共(public)类 LocationWebService 扩展 AsyncTask {

public LocationWebService() {
// TODO Auto-generated constructor stub
}

@Override
protected Boolean doInBackground(String... arg0) {
String lat = arg0[0];
String lng = arg0[1];
String url = arg0[2];
String email = arg0[3];
Log.e("LAT",arg0[0]);
Log.e("LNG",arg0[1]);
Log.e("URL",arg0[2]);
Log.e("EMAIL",arg0[3]);
InputStream is = null;
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("latitude", lat));
nameValuePairs.add(new BasicNameValuePair("longitude", lng));
nameValuePairs.add(new BasicNameValuePair("email", email));
String result = null;

try{
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
is = entity.getContent();

BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"), 8);
StringBuilder sb = new StringBuilder();

String line = null;
while ((line = reader.readLine()) != null)
{
sb.append(line + "\n");
}
result = sb.toString();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}

}

最佳答案

除非您的网络或服务器出现问题,否则我认为您上面的代码不会花费 10 秒那么长的时间。

关于android - 上传或下载经纬度到服务器的最快方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38319566/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com