简体   繁体   中英

Can't get Android WebView's postUrl to work with a port

My WebView is working perfectly until I add in a port. At which point I don't see any sort of error and I see nothing in my HTTP traffic.

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");        
}

I know there is some other weird stuff going on in my code but for now I'd like to just focus on getting postUrl to work.

EDIT: In the logcat I found this not sure if it is relevant.

10-19 13:44:21.560: D/SntpClient(59): request time failed: java.net.SocketException: Address family not supported by protocol

Please try with WebChromeClient and override following methods:

   @Override
public void onConsoleMessage(String message, int lineNumber, String sourceID) {
    // TODO Auto-generated method stub
    Log.v("ChromeClient", "invoked: onConsoleMessage() - " + sourceID + ":"
            + lineNumber + " - " + message);
    super.onConsoleMessage(message, lineNumber, sourceID);
}

@Override
public boolean onConsoleMessage(ConsoleMessage cm) {
    Log.v("ChromeClient", cm.message() + " -- From line "
            + cm.lineNumber() + " of "
            + cm.sourceId() );
    return true;
}

to debug the issue..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM