0

我在基于代理的环境中工作,无法通过模拟器使用 SOAP Web 服务。有谁知道如何在基于代理的环境中使用 SOAP Web 服务?

我创建了这个类:

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 = new HttpTransportBasicAuth(url); androidHttpTransportSE.call(url);

但它返回空指针异常,我无法找出在基于代理的网络中访问 Web 服务的解决方案。请帮助

提前致谢

4

0 回答 0