由网友(﹉﹊未知)分享简介:我有一个Android应用程序,需要用户名和密码登录。我需要通过展示已成功注册一个警告框,进入注册页面的细节来保存用户名和密码在远程服务器。当用户打开下一次应用,他将登录。我想使用的客户机/服务器机制。之后,我得到的回应,我想要么使用SAX解析器或肥皂解析它。我搜索了很多通过谷歌,但我没有找到一个正确的例子。由于我是新...
我有一个Android应用程序,需要用户名和密码登录。我需要通过展示已成功注册
一个警告框,进入注册页面的细节来保存用户名和密码在远程服务器。当用户打开下一次应用,他将登录。我想使用的客户机/服务器机制。之后,我得到的回应,我想要么使用SAX解析器或肥皂解析它。我搜索了很多通过谷歌,但我没有找到一个正确的例子。由于我是新来的WebServices,我没能解决它。请帮我。
的EditText输入1 =(EditText上)findViewById(R.id.usertext);EditText上输入2 =(EditText上)findViewById(R.id.Passtext);字符串username = input1.getText()的toString()。。字符串密码= input2.getText()的toString();
解决方案
包com.google.android.Test;进口org.ksoap2.SoapEnvelope;进口org.ksoap2.serialization.SoapObject;进口org.ksoap2.serialization.SoapSerializationEnvelope;进口org.ksoap2.transport.HttpTransport;进口android.app.Activity;进口android.os.Bundle;进口android.widget.TextView;公共类为MyWebService扩展活动{ 私有静态最后弦乐SOAP_ACTION =HelloYou; 私有静态最后弦乐METHOD_NAME =getHello; 私有静态最后弦乐NAMESPACE =瓮:HelloYou 私有静态最终字符串URL =HTTP://localhost/lab/service.php 私有对象resultRequestSOAP = NULL; @覆盖 公共无效的onCreate(捆绑冰柱) { super.onCreate(冰柱); TextView的电视=新的TextView(本); 的setContentView(电视); SoapObject要求=新SoapObject空间(namespace,METHOD_NAME); // SoapObject request.addProperty(名字,约翰); request.addProperty(姓氏,威廉姆斯); SoapSerializationEnvelope信封=新SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.setOutputSoapObject(请求); HttpTransport androidHttpTransport =新HttpTransport(URL); 尝试 { androidHttpTransport.call(SOAP_ACTION,信封); resultsRequestSOAP = envelope.getResponse(); 的String [] =结果(字符串[])resultsRequestSOAP; tv.setText(结果[0]); } 赶上(例外AE) { aE.printStackTrace();; } }}
I have an Android application which needs username and password to login. I need to save the username and password in a remote server by entering the details in the register page with an alert box showing Registered successfully
. When the user opens the app next time, he will login. I want to use client/server mechanism. After I get the response, I want to parse it either using sax parser or soap. I searched a lot through Google, but I didn't find a correct example. As I am new to webservices, I couldn't solve it. Please help me.
EditText input1 = (EditText) findViewById(R.id.usertext);
EditText input2 = (EditText) findViewById(R.id.Passtext);
String username = input1.getText().toString();
String password = input2.getText().toString();
解决方案
package com.google.android.Test;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransport;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class myWebService extends Activity
{
private static final String SOAP_ACTION = "HelloYou";
private static final String METHOD_NAME = "getHello";
private static final String NAMESPACE = "urn:HelloYou";
private static final String URL = "http://localhost/lab/service.php";
private Object resultRequestSOAP = null;
@Override
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
TextView tv = new TextView(this);
setContentView(tv);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
//SoapObject
request.addProperty("firstname", "John");
request.addProperty("lastname", "Williams");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransport androidHttpTransport = new HttpTransport(URL);
try
{
androidHttpTransport.call(SOAP_ACTION, envelope);
resultsRequestSOAP = envelope.getResponse();
String[] results = (String[]) resultsRequestSOAP;
tv.setText( results[0]);
}
catch (Exception aE)
{
aE.printStackTrace ();;
}
}
}
相关推荐
最新文章