webView 表单将空格发布为“+”而不是“%20” Xamarin Android
webView form posts spaces as "+" instead of "%20" Xamarin Android
我正在按照覆盖 WebViewClient.ShouldOverrideUrlLoading 的混合应用程序示例来拦截链接和帖子。由于这不适用于 POST,我将 GET 用于表单。但是,表单控件值被编码并放入 URL 传递给 ShouldOverrideUrlLoading ,但编码使用“+”而不是“%20”,就像我的 ASP.NET 网络应用程序版本一样。我可以简单地做:
url = url.Replace("+", " ");
但是如果用户想要在编辑字段中使用“+”怎么办?强制他们使用某种像“%43”and/or“+”这样的转义是唯一的方法吗?这样我就需要做类似的事情:
url = url.Replace("+", " ");
url = url.Replace("%2543", "+");
url = url.Replace("%26%2343%3B", "+");
这似乎是 Url 编码表单字段的标准。
When data that has been entered into HTML forms is submitted, the form field names and values are encoded and sent to the server in an HTTP request message using method GET or POST, or, historically, via email.[2] The encoding used by default is based on an early version of the general URI percent-encoding rules,[3] with a number of modifications such as newline normalization and replacing spaces with "+" instead of "%20". The Internet media type of data encoded this way is application/x-www-form-urlencoded, and it is currently defined (still in a very outdated manner) in the HTML and XForms specifications. In addition, the CGI specification contains rules for how web servers decode data of this type and make it available to applications.
因此您必须取消对 URL 的编码才能使用它,并将加号适当地更改为空格。
我正在按照覆盖 WebViewClient.ShouldOverrideUrlLoading 的混合应用程序示例来拦截链接和帖子。由于这不适用于 POST,我将 GET 用于表单。但是,表单控件值被编码并放入 URL 传递给 ShouldOverrideUrlLoading ,但编码使用“+”而不是“%20”,就像我的 ASP.NET 网络应用程序版本一样。我可以简单地做:
url = url.Replace("+", " ");
但是如果用户想要在编辑字段中使用“+”怎么办?强制他们使用某种像“%43”and/or“+”这样的转义是唯一的方法吗?这样我就需要做类似的事情:
url = url.Replace("+", " ");
url = url.Replace("%2543", "+");
url = url.Replace("%26%2343%3B", "+");
这似乎是 Url 编码表单字段的标准。
When data that has been entered into HTML forms is submitted, the form field names and values are encoded and sent to the server in an HTTP request message using method GET or POST, or, historically, via email.[2] The encoding used by default is based on an early version of the general URI percent-encoding rules,[3] with a number of modifications such as newline normalization and replacing spaces with "+" instead of "%20". The Internet media type of data encoded this way is application/x-www-form-urlencoded, and it is currently defined (still in a very outdated manner) in the HTML and XForms specifications. In addition, the CGI specification contains rules for how web servers decode data of this type and make it available to applications.
因此您必须取消对 URL 的编码才能使用它,并将加号适当地更改为空格。