安卓(Java)的简单发送和接收与服务器 - 快速安装挑战 [英] Android (Java) Simple Send and recieve with Server - Fast Setup Challenge

查看:120
本文介绍了安卓(Java)的简单发送和接收与服务器 - 快速安装挑战的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个Android应用程序,我正在寻找最快的(在设置方面)的方式,我将数据发送到服务器并接收信息发回的请求。

我们正在谈论基本的东西。我有告诉我了用户如何使用我的应用程序的日志文件(测试版,我就不会运行Active Script不断记录通常是用户体验),我想传达给我的服务器(我还没有安装)。

我不需要安全,我并不需要高吞吐量和并发连接(我有3个手机一起玩),但我确实需要快速的设置了!

我记得的日子,设立XAMPP特别呆头呆脑,那么也许我可以用PHP从手机发送文件到服务器?

服务器在理想情况下能够以一个GET这将让我发回的一些SQL语句,从而最终影响用户界面响应。 (它的意思,以适应presented选择取决于那些最常用的)。

如果你拥有它,我用PHP大约4年前,将走这条路线,如果这是最好的,但如果有某种新一届港开闭二进制流载歌载舞方法已superseeded的选择,我会爱就知道了。

本教程似乎是有用的,但我并不真正需要的对象的序列化,只是文本文件来回,COM pressed自然。

Android自带的的Apache HTTP客户端4.0 建以及java.net.URL中和java.net.HttpURLConnection中,我宁愿不要太多增加录音功能支持我的应用程序与第三方库。

请记住,我设置了服务器端,以及使我在寻找的code的整体最低线!

谢谢

GAV株系

解决方案

 私人无效送出数据(ProfileVO PVO){

  Log.i(的getClass()getSimpleName(),送任务 - 启动);

    的HttpParams P =新BasicHttpParams();
    p.setParameter(姓名,pvo.getName());

  //实例化一个HttpClient的
  HttpClient的客户=新DefaultHttpClient(对);

  //实例化一个GET HTTP方法
  尝试 {
    HTT presponse响应= client.execute(新HTTPGET(http://www.itortv.com/android/sendName.php));
    InputStream的是= response.getEntity()的getContent()。
    //你可以转换的InputStream一个字符串:http://senior.ceng.metu.edu.tr/2009/praeda/2009/01/11/a-simple-restful-client-at-android/
}赶上(ClientProtocolException E){
    // TODO自动生成的catch块
    e.printStackTrace();
}赶上(IOException异常E){
    // TODO自动生成的catch块
    e.printStackTrace();
}



  Log.i(的getClass()getSimpleName(),送任务 - 结束。);

}
 

I'm writing an Android App and I'm looking for the fastest (In terms of setup) way for me to send data to a server and receive information back on request.

We're talking basic stuff. I have a log file which tells me how a user is using my application (In beta, I wouldn't runin a user experience by constantly logging usually) and I want to communicate that to my server (That I haven't setup).

I don't need security, I don't need high throughput or concurrent connections (I have 3 phones to play with) but I do need to set it up fast!

I remember back in the day that setting up XAMPP was particularly brainless, then maybe I could use PHP to send the file from the phone to the Server?

The Server would ideally be able to respond to a GET which would allow me to send back some SQL statements which ultimately affect the UI. (It's meant to adapt the presented options depending on those most commonly used).

So there you have it, I used PHP about 4 years ago and will go down that route if it's the best but if there's some kind of new fangled port open closing binary streaming singing and dancing method that has superseeded that option I would love to know.

This tutorial seems useful but I don't really need object serialization, just text files back and forth, compressed naturally.

Android comes with the Apache HTTP Client 4.0 built in as well as java.net.URL and java.net.HttpUrlConnection, I'd rather not add too much bult to my App with third party libraries.

Please remember that I'm setting up the server side as well so I'm looking for an overall minimum lines of code!

Thanks,

Gav

解决方案

 private void sendData(ProfileVO pvo) {

  Log.i(getClass().getSimpleName(), "send  task - start");

    HttpParams p=new BasicHttpParams();
    p.setParameter("name", pvo.getName());

  //Instantiate an HttpClient
  HttpClient client = new DefaultHttpClient(p);

  //Instantiate a GET HTTP method
  try {
    HttpResponse response=client.execute(new HttpGet("http://www.itortv.com/android/sendName.php"));
    InputStream is=response.getEntity().getContent();
    //You can convert inputstream to a string with: http://senior.ceng.metu.edu.tr/2009/praeda/2009/01/11/a-simple-restful-client-at-android/
} catch (ClientProtocolException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}



  Log.i(getClass().getSimpleName(), "send  task - end");

}

这篇关于安卓(Java)的简单发送和接收与服务器 - 快速安装挑战的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆