Tôi đang gặp phải một số vấn đề lạ, Chỉ ứng dụng của tôi không hoạt động khi tôi chuyển sang dịch vụ 3G (Có proxy) nhưng nó hoạt động tốt trong WIFI và 3G (không có proxy).Ứng dụng Android hoạt động trên WIFI và 3G (Không có proxy) nhưng không hoạt động trên 3G (Nếu proxy và cổng được gán)
Mặc định proxy và cổng do Starhub (nhà cung cấp mạng) của tôi:
Proxy: 10.12.1.2
Port: 80
Đối với dữ liệu, tôi đang gửi yêu cầu đến máy chủ web xà phòng của tôi.
Đây là mã của tôi:
public class SearchThread extends Thread {
private String mUrl;
private SoapSerializationEnvelope mEnvelop;
private Handler mHandler;
private String mSoapAction;
private KeepAliveHttpsTransportSE mTransport;
public SearchThread(String url) {
this.mUrl = url;
}
@Override
public void run() {
mEnvelop = new SoapSerializationEnvelope(SoapSerializationEnvelope.VER11);
mEnvelop.setOutputSoapObject(interfaceListener.getSoapObject(element));
mSoapAction = interfaceListener.getSoapAction(element);
try {
TrustManagerManipulator.allowAllSSL();
mTransport = new KeepAliveHttpsTransportSE(URLS.URL_MAIN, 443, mUrl, 60000);
mTransport.call(mSoapAction, mEnvelop);
if (this.isInterrupted()) {
Log.v(TAG,"Interrupted");
return;
}
recevedSoapResponse(mEnvelop.getResponse());
} catch (SocketException ex) {
Log.e("Error : ", "Error on soapPrimitiveData() " + ex.getMessage());
ex.printStackTrace();
} catch (IOException e) {
interfaceListener.recievedParsingResults(
PARSER.RESULT.CONNECTION_FAILED, element, mHandler, mView);
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
interfaceListener.recievedParsingResults(
PARSER.RESULT.INTERNAL_ERROR, element, mHandler, mView);
}
}
private void recevedSoapResponse(Object response) {
//Parsing XML here.
}
public class KeepAliveHttpsTransportSE extends HttpsTransportSE
{
private final String host;
private final int port;
private final String file;
private final int timeout;
private ServiceConnection serviceConnection;
public KeepAliveHttpsTransportSE (String host, int port, String file, int timeout) {
super(host, port, file, timeout);
this.host = host;
this.port = port;
this.file = file;
this.timeout = timeout;
}
//@Override
public ServiceConnection getServiceConnection() throws IOException
{
if (serviceConnection == null) {
serviceConnection = new HttpsServiceConnectionSE(host, port, file, timeout);
serviceConnection.setRequestProperty("Connection", "keep-alive");
}
return serviceConnection;
}
}
}
Và đây là mã SSL của tôi:
public class TrustManagerManipulator implements X509TrustManager {
private static TrustManager[] trustManagers;
private static final X509Certificate[] acceptedIssuers = new X509Certificate[] {};
public boolean isClientTrusted(X509Certificate[] chain) {
return true;
}
public boolean isServerTrusted(X509Certificate[] chain) {
return true;
}
public static void allowAllSSL() {
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
SSLContext context = null;
if (trustManagers == null) {
trustManagers = new TrustManager[] { new TrustManagerManipulator() };
}
try {
context = SSLContext.getInstance("TLS");
context.init(null, trustManagers, new SecureRandom());
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
}
HttpsURLConnection.setDefaultSSLSocketFactory(context
.getSocketFactory());
}
public void checkClientTrusted(X509Certificate[] chain, String authType)
throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] chain, String authType)
throws CertificateException {
}
public X509Certificate[] getAcceptedIssuers() {
return acceptedIssuers;
}
}
Ngoại lệ:
09-27 12:21:03.295: W/System.err(8924): java.net.SocketException: Socket is closed
09-27 12:21:03.295: W/System.err(8924): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.checkOpen(OpenSSLSocketImpl.java:262)
09-27 12:21:03.295: W/System.err(8924): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:273)
09-27 12:21:03.295: W/System.err(8924): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:257)
09-27 12:21:03.295: W/System.err(8924): at libcore.net.http.HttpConnection.setupSecureSocket(HttpConnection.java:210)
09-27 12:21:03.295: W/System.err(8924): at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:477)
09-27 12:21:03.295: W/System.err(8924): at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:441)
09-27 12:21:03.295: W/System.err(8924): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282)
09-27 12:21:03.295: W/System.err(8924): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232)
09-27 12:21:03.295: W/System.err(8924): at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)
09-27 12:21:03.300: W/System.err(8924): at libcore.net.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:188)
09-27 12:21:03.300: W/System.err(8924): at libcore.net.http.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:280)
09-27 12:21:03.300: W/System.err(8924): at org.ksoap2.transport.HttpsServiceConnectionSE.openOutputStream(HttpsServiceConnectionSE.java:98)
09-27 12:21:03.300: W/System.err(8924): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:157)
09-27 12:21:03.300: W/System.err(8924): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:96)
09-27 12:21:03.300: W/System.err(8924): at com.mobile.utils.parser.SearchThread.run(SearchThread.java:25)
bổ sung Thông tin: Tất cả các ứng dụng khác đang chạy trên 3 Mạng G (có/không có cài đặt proxy) và trong ứng dụng của tôi chỉ yêu cầu SOAP không hoạt động.
Tôi đã thử tất cả các trường hợp có thể, nhưng không có may mắn. Vui lòng cung cấp cho tôi một số yếu tố đầu vào.
Xin cảm ơn trước.
này giải quyết vấn đề của tôi. Nó phải được chấp nhận IMO. –