Android的Web服务Implememnation [英] Android Web Service Implememnation

查看:203
本文介绍了Android的Web服务Implememnation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新android开发。我很学东西快。

I am new to android development. I am quite learning things faster.

我有几个疑问在这里发布:

I have few queries to Post here:

  1. 我需要code调用Web服务在我的Andr​​oid的登录屏幕。 IE浏览器。当用户输入自己的用户名和密码在登录屏幕,调用Web服务并检查有效的用户或不能从我的服务器和dispaly错误。

  1. I need code for Calling web service for my Login Screen in Android. ie. when user enters his username and password in the login screen, call web service and check valid user or not from my server and dispaly error.

我也有问题的WebView Android中。我总是获得与web视图页面未找到的错误。

I also have problem with webview in Android. Always i get the webview with "PAGE NOT FOUND" error.

请帮我解决我的问题。

在此先感谢

问候, 拉哈夫拉贾戈帕兰

Regards, Raghav Rajagopalan

推荐答案

1)。我认为这个问题并不指的WebView问题。从你的应用程序中,您可以创建使用连接到服务器的java.net.Socket java.nio.channels.SocketChannel中。我preFER的SocketChannel,因为它有一个基本的插座不具备的一些功能(如非阻塞模式)。

1.) I assume that this question does not refer to the WebView question. From within your app, you can create connections to your server using java.net.Socket or java.nio.channels.SocketChannel. I prefer SocketChannel as it has some features that the basic Socket does not have (e.g. non-blocking mode).

使用这个类它很容易与您的服务器进行通信,例如:

With this class it's fairly easy to communicate with your server, for example:

// this code has not been tested (!)
// Username and Password will be sent in a single string to the server, namely "username|password"
String username = "foo";
String password = "bar";

// Open Socket connection to the Server example.com at Port 12345
SocketChannel sock = SocketChannel.open(new InetSocketAddress("example.com", 12345));

// send user credentials to server
String data = username + "|" + password;
sock.write(ByteBuffer.wrap(data.getBytes()));

// await response from server
ByteBuffer result = ByteBuffer.allocate(8); // 8 byte-large container for result
fSocket.read(result);

// The first byte of the response decides wether login failed or succeeded (just as an example!)
if (result.get(0) == 1) {
  // login succeeded
} else {
  // login failed
}

不过,如果你使用的阻塞模式,我建议将连接处理在自己的线程。有关套接字通信更多资料,请参见插座和的的SocketChannel 文档。

2)如果没有找到页面,也许URL是在一个错误的格式?一些细节会有所帮助。

2.) If the Page is not found, maybe the URL is in a wrong format? Some details would help here.

这篇关于Android的Web服务Implememnation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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