I have a web service which has following operation
public String loginVerify(String email, String password){
}
and I am consuming this service on android using ksoap2 library. This is code
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();
I am getting null pointer exception as error and after debugging I came to know that the input parameters (email, password)
are null. Where is the problem.
Try to add your authentication data to header:
envelope.headerOut = new Element[1];
envelope.headerOut[0] = buildAuthHeader();
and method:
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;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.