gpt4 book ai didi

Android: (webservices) 如何在远程服务器中存储数据并检索它

转载 作者:行者123 更新时间:2023-11-29 22:24:31 25 4
gpt4 key购买 nike

我有一个 Android 应用程序需要用户名和密码才能登录。我需要将用户名和密码保存在远程服务器中,方法是在注册页面中输入详细信息,并在警告框中显示 Registered successfully。当用户下次打开应用程序时,他将登录。我想使用客户端/服务器机制。收到响应后,我想使用 sax 解析器或 soap 对其进行解析。我通过谷歌搜索了很多,但没有找到正确的例子。由于我是网络服务的新手,我无法解决它。请帮助我。

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

关于Android: (webservices) 如何在远程服务器中存储数据并检索它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6289206/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com