gpt4 book ai didi

java - 在android中使用kSOAP连接到web服务

转载 作者:行者123 更新时间:2023-12-02 04:11:12 27 4
gpt4 key购买 nike

我正在尝试将 Web 服务与 kSOAP 库连接。代码将用户名和密码、姓名和家庭等 4 个字段发送到服务器,但在服务器中所有内容都收到 null !这是我的代码问题出在哪里?WebService.java

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.util.Log;


public class WebService {
private static String NAMESPACE = "xxxxxxxxxxxx";
public final static String URL = "xxxxxxxxxxxx";

private static String SOAP_ACTION = "xxxxxxxxxxxxxxx";
private static final String METHOD = "Register";
public static String invokeWS() {
String resTxt = null;

SoapObject request = new SoapObject(NAMESPACE, METHOD);

request.addProperty("username","user");
request.addProperty("password","pass");
request.addProperty("name","MyName");
request.addProperty("family","MyFamily");
Log.v("", ""+request);
SoapSerializationEnvelope envelope =
new SoapSerializationEnvelope( SoapEnvelope.VER12);

envelope.setOutputSoapObject(request);

HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

try {
androidHttpTransport.call(SOAP_ACTION+METHOD, envelope);
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
resTxt = response.toString();
} catch (Exception e) {
e.printStackTrace();
Log.e("",""+e);
resTxt = "Error !!!!";
}
return resTxt;
}
}

并在MainActivity.java中调用invokeWS()

 AsyncCallWS task = new AsyncCallWS();
//Call execute
task.execute();
private class AsyncCallWS extends AsyncTask<String, Void, Void> {
@Override
protected Void doInBackground(String... params) {
displayText = WebService.invokeWS();
return null;
}
@Override
protected void onPostExecute(Void result) {
//Set response
Log.v("", "Recive : "+displayText);
}
@Override
protected void onPreExecute() {
}
@Override
protected void onProgressUpdate(Void... values) {
}
}

最佳答案

将此行添加到您的代码中:

envelope.dotNet=true

关于java - 在android中使用kSOAP连接到web服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33780201/

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