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

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

问题描述

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

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).

我不需要安全性,我不需要高吞吐量或并发连接(我有3部手机可以玩)但我确实需要快速设置!

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!

我记得当天设置XAMPP特别无脑,那么也许我可以使用PHP将文件从手机发送到服务器?

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?

服务器理想情况下能够响应GET,这将允许我发回一些最终影响UI的SQL语句。 (这意味着根据最常用的选项调整显示的选项。)

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).

所以你有它,我大约4年前使用PHP并将沿着那条路走下去如果这是最好的,但如果有某种新的fangled端口打开关闭二进制流媒体唱歌和跳舞方法已取代该选项我很想知道。

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内置了 Apache HTTP Client 4.0 以及java.net.URL和java.net.HttpUrlConnection,I我宁愿不要在我的应用程序中添加太多的第三方库。

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!

推荐答案

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");
}

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

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