我的WebView在我添加端口之前工作正常。在這一點上,我沒有看到任何類型的錯誤,並且我的HTTP流量中什麼也看不到。無法讓Android WebView的postUrl使用端口
private Context vContext;
private String vPackageName;
private String vPlacementID;
static private double TRACK_VERSION = 1.0;
static private String TRACK_HOST = "foobar.com:8007";
static private String TRACK_HANDLER = "/event";
public void reportAppOpen(Context context, String placementID) {
Log.d("FOO", "Tracking");
if (context == null) {
return;
}
vContext = context;
vPackageName = vContext.getPackageName();
vPlacementID = placementID;
WebView webview = new WebView(context);
webview.setVisibility(WebView.GONE);
webview.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Log.d("FOO", "error code:" + errorCode);
super.onReceivedError(view, errorCode, description, failingUrl);
}
});
webview.getSettings().setJavaScriptEnabled(true);
List<NameValuePair> params = trackingParams();
String paramString = URLEncodedUtils.format(params, "utf-8");
String url = "http://" + TRACK_HOST + TRACK_HANDLER;
webview.postUrl(url, EncodingUtils.getBytes(paramString, "base64"));
Log.d("FOO", "Loading URL");
}
我知道有一些其他怪異的東西在我的代碼怎麼回事,但現在我想只專注於獲得postUrl
工作。
編輯:在logcat中我發現這不知道它是否有關。
10-19 13:44:21.560: D/SntpClient(59): request time failed: java.net.SocketException: Address family not supported by protocol
你得到的logcat的東西嗎? –
我發現'10-19 13:44:21.560:D/SntpClient(59):請求時間失敗:java.net.SocketException:地址族不受協議支持。看起來它似乎認爲uri可能無效?但是這個網址顯然是有效的,除非有其他途徑通過這個港口。 – hadees
即SntpClient錯誤與您的應用程序無關。 –