我有一个具有以下操作的Web服务
public String loginVerify(String email, String password){
}
我正在使用ksoap2库在Android上使用此服务。这是代码
SoapObject request = new SoapObject(NAMESPACE, "loginVerify");
PropertyInfo emailProperty=new PropertyInfo();
PropertyInfo passwordProperty=new PropertyInfo();
emailProperty.setName("email");
emailProperty.setValue(emailText);
passwordProperty.setName("password");
passwordProperty.setValue(passwordText);
passwordProperty.setType(String.class);
emailProperty.setType(String.class);
request.addProperty(emailProperty);
request.addProperty(passwordProperty);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try
{
androidHttpTransport.debug = true;
androidHttpTransport.call(SOAP_ACTION, envelope);
String dumprequest=androidHttpTransport.requestDump;
String dumpresponse=androidHttpTransport.responseDump;
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
String result = response.toString();
我得到空指针异常为错误,调试后我才知道输入参数(email, password)
为空。问题出在哪里。
答案 0 :(得分:0)
尝试将您的身份验证数据添加到标头:
envelope.headerOut = new Element[1];
envelope.headerOut[0] = buildAuthHeader();
和方法:
private Element buildAuthHeader() {
Element h = new Element().createElement(SERVICE_NAMESPACE, "MyHeader");
Element username = new Element().createElement(SERVICE_NAMESPACE, "email");
username.addChild(Node.TEXT, "your_email");
h.addChild(Node.ELEMENT, username);
Element pass = new Element().createElement(SERVICE_NAMESPACE, "password");
pass.addChild(Node.TEXT, "your_password");
h.addChild(Node.ELEMENT, pass);
return h;
}