3

I want to stream to WebView inside a Anrdoid App.

My code is:

WebView cam = (WebView) findViewById(R.id.Cam);
        cam.getSettings().setLoadWithOverviewMode(true);
        cam.getSettings().setUseWideViewPort(true);
        cam.getSettings().setBuiltInZoomControls(true);
        cam.getSettings().setPluginState(WebSettings.PluginState.ON);
        cam.getSettings().setPluginState(WebSettings.PluginState.ON);
        cam.loadUrl("http://192.168.0.10");

It works in emulator but if I install the App at smartphone it doesnt work. I get an error

Header fields are too long for the server to interpret

How do get rid of this error?

Bharathi
  • 1,015
  • 13
  • 41
Rachid Id
  • 31
  • 1
  • 3

2 Answers2

6

Edit sdkconfig and increase CONFIG_HTTPD_MAX_REQ_HDR_LEN e.g. like this:

CONFIG_HTTPD_MAX_REQ_HDR_LEN=1024

The default is 512. Don't set it too high to avoid wasting RAM, remember that ESP32 doesn't have much RAM.

Also it's best to set the User-Agent header in your WebView, otherwise a system-default User-Agent will be used, which can be longer or shorter depending on the actual Android device.

    cam.getSettings().setUserAgentString("Mozilla/5.0 (my app)");

The above might just fit within the default 512 bytes for the request length.

rustyx
  • 80,671
  • 25
  • 200
  • 267
1

I had the same problem but with Unity. In my app, I was struggling with

Header fields are too long for the server to interpret

but Chrome browser in android was showing it right. I changed ESP32 code but not worked. When I try opening it in desktop mode it worked. You had to change your "User Agent" setting.

 String newUA= "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko/20100101 Firefox/4.0";
 mWebView.getSettings().setUserAgentString(newUA);

like in: Setting WebView to view Desktop Site and Not Mobile Site