尝试通过 HTTPS 向服务器发送 POST 请求时收到 NullPointerException。这不是自签名证书(由 CheapSSLs 颁发)。
这是我收到的错误:
06-21 18:52:37.757: E/AndroidRuntime(17985): FATAL EXCEPTION: AsyncTask #1
06-21 18:52:37.757: E/AndroidRuntime(17985): java.lang.RuntimeException: An error occured while executing doInBackground()
06-21 18:52:37.757: E/AndroidRuntime(17985): at android.os.AsyncTask$3.done(AsyncTask.java:200)
06-21 18:52:37.757: E/AndroidRuntime(17985): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
06-21 18:52:37.757: E/AndroidRuntime(17985): at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
06-21 18:52:37.757: E/AndroidRuntime(17985): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
06-21 18:52:37.757: E/AndroidRuntime(17985): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
06-21 18:52:37.757: E/AndroidRuntime(17985): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
06-21 18:52:37.757: E/AndroidRuntime(17985): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
06-21 18:52:37.757: E/AndroidRuntime(17985): at java.lang.Thread.run(Thread.java:1019)
06-21 18:52:37.757: E/AndroidRuntime(17985): Caused by: java.lang.NullPointerException
06-21 18:52:37.757: E/AndroidRuntime(17985): at org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:433)
06-21 18:52:37.757: E/AndroidRuntime(17985): at org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnectionImpl$HttpsEngine.makeConnection(HttpsURLConnectionImpl.java:378)
06-21 18:52:37.757: E/AndroidRuntime(17985): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:205)
06-21 18:52:37.757: E/AndroidRuntime(17985): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:614)
06-21 18:52:37.757: E/AndroidRuntime(17985): at org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:268)
我的代码如下:
URL url = new URL(mUrl);
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("192.168.1.134", 8888));
HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection(proxy);
urlConnection.setRequestMethod("POST");
urlConnection.setDoInput(true);
urlConnection.setDoOutput(true);
MultipartBodyBuilder builder = new MultipartBodyBuilder();
builder.build(params);
urlConnection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + builder.mBoundary);
urlConnection.setFixedLengthStreamingMode(builder.getContentLength());
DataOutputStream out = new DataOutputStream(new BufferedOutputStream(urlConnection.getOutputStream()));
代码在 getOutputStream 上崩溃。
任何帮助将不胜感激。