Java 在android中基于代理的环境中使用SOAP web服务
我在一个基于代理的环境中工作,在这个环境中,我无法通过emulator使用SOAP web服务。有人知道如何在基于代理的环境中使用SOAPWeb服务吗 我创建了这个类:Java 在android中基于代理的环境中使用SOAP web服务,java,android,soap,proxy,basic-authentication,Java,Android,Soap,Proxy,Basic Authentication,我在一个基于代理的环境中工作,在这个环境中,我无法通过emulator使用SOAP web服务。有人知道如何在基于代理的环境中使用SOAPWeb服务吗 我创建了这个类: import java.io.IOException; import java.net.Proxy; import org.kobjects.base64.Base64; import org.ksoap2.transport.HttpTransportSE; import org.ksoap2.transport.Servic
import java.io.IOException;
import java.net.Proxy;
import org.kobjects.base64.Base64;
import org.ksoap2.transport.HttpTransportSE;
import org.ksoap2.transport.ServiceConnection;
//class to handle authentication in a proxy based environment
public class HttpTransportBasicAuth extends HttpTransportSE {
//username and password for accessing a proxy based network
private String username;
private String password;
public HttpTransportBasicAuth(String url, String username, String password) {
super(url);
this.username = username;
this.password = password;
}
@Override
public ServiceConnection getServiceConnection() throws IOException {
ServiceConnection serviceConnection = super.getServiceConnection();
addBasicAuthentication(serviceConnection);
return serviceConnection;
}
protected void addBasicAuthentication(ServiceConnection serviceConnection)
throws IOException {
if (username != null && password != null) {
StringBuffer buffer = new StringBuffer(username);
buffer.append(':').append(password);
byte[] bytes = buffer.toString().getBytes();
buffer.setLength(0);
buffer.append("Basic ");
Base64.encode(bytes, 0, bytes.length, buffer);
serviceConnection.setRequestProperty
("Authorization", buffer.toString());
}
}
}
然后我创建了它的对象,如:
HttpTransportBasicAuth androidHttpTransportSE=新的HttpTransportBasicAuth(url);
androidHttpTransportSE.call(url)
但是它返回空指针异常,我无法找到在基于代理的网络中访问webservice的解决方案。请帮助
提前感谢您如何使用基于soap的Web服务?您能显示您的代码片段吗?SoapObject请求=新的SoapObject(名称空间、方法\名称);addProperty(“设备id”,“0:0:0:0:0”);SoapSerializationEnvelope=新的SoapSerializationEnvelope(SoapEnvelope.VER11);envelope.dotNet=true;envelope.setOutputSoapObject(请求);System.out.println(“信封==>”+信封.bodyOut.toString());androidHttpTransport.debug=true;调用(SOAP_操作,信封);SoapObject obj=(SoapObject)envelope.bodyIn;System.out.println(obj.toString());您是否可以使用HttpTransport而不是androidHttpTransport。请参阅,androidHttpTransport是HttpTransportSE的对象