我应该怎么做,从偏食连接到服务器 - 的Android? [英] What should I do to connect to Server from eclipse - Android?
问题描述
大师,我是一个律失去了对这个话题。这里是我想要做的崩溃。
Gurus, I am a lil lost on this topic. Here's a breakdown of what I'm trying to do.
[用户/ Android设备]发送位置信息到服务器 - > [服务器]
[User/Android Device] sends location info to a server -> [server]
[服务器]返回的项目已使用SQL从排序列表中 - > [DB]
[server] returns a list of items that has been sorted using sql from a - >[db]
[服务器]获取表信息,并返回给用户 - > [用户/ Android设备]
[server] obtains table information and returns to user -> [User/Android Device]
因此从上面的situtation,我很失落,以我如何使用Eclipse中的服务器进行通信?我用PHP或ASP在java中(如果可能的话:S)?或者可能我指出来的地方到一个链接来阅读关于
so from the above situtation, I am lost as to how do i communicate with the server using eclipse? do i use php or asp in java(if it's possible :S) or could i be pointed to somewhere to a link to read on?
从服务器将会有处理该请求正确的PHP / ASP页面?
from the server there will be a php/asp page that handles the request correct?
希望同行高手们得到什么,我想说
Hope fellow gurus get what i'm trying to say
推荐答案
调用下面的方法来从它连接到任何URL和读取响应数据。 什么那么的网址,你会打。 URL将是任何PHP或ASP或JSP页面或任何服务器端脚本语言。下面的方法有什么关系呢。什么那么的URL页面会返回,将在您的日志纪录输入。检查日志猫读取结果
call the following method to connect to any url and read response data from it. What so ever the URL you will hit. Url will be of any php or asp or jsp page or in any server side scripting language. The following method has nothing do with it. what so ever the url page will return that will be entered in your Log records. check Log cat for read result
private void connectToServerAndReadData()
{
HttpURLConnection conn;
boolean result = false;
try{
// Enter any URL here you want to connect
URL url = new URL("http://php1.funnymedialinks.com/scribd/rcheck.php");
// Open a HTTP connection to the URL
conn = (HttpURLConnection) url.openConnection();
// conn.connect();
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line ;
while ((line = rd.readLine()) != null) {
Log.v("Readed Data from Server ","data- "+line);
}
rd.close();
}catch(MalformedURLException e){
e.printStackTrace();
}
catch(IOException e){
e.printStackTrace();
}
catch(Exception e){
e.printStackTrace();
}
}
这篇关于我应该怎么做,从偏食连接到服务器 - 的Android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!