{"action":"created","issue":{"url":"https://api.github.com/repos/NLog/NLog/issues/1629","repository_url":"https://api.github.com/repos/NLog/NLog","labels_url":"https://api.github.com/repos/NLog/NLog/issues/1629/labels{/name}","comments_url":"https://api.github.com/repos/NLog/NLog/issues/1629/comments","events_url":"https://api.github.com/repos/NLog/NLog/issues/1629/events","html_url":"https://github.com/NLog/NLog/issues/1629","id":175791287,"number":1629,"title":"Incorrect urlencode of WebService target","user":{"login":"Master-Inspire","id":9047578,"avatar_url":"https://avatars.githubusercontent.com/u/9047578?v=3","gravatar_id":"","url":"https://api.github.com/users/Master-Inspire","html_url":"https://github.com/Master-Inspire","followers_url":"https://api.github.com/users/Master-Inspire/followers","following_url":"https://api.github.com/users/Master-Inspire/following{/other_user}","gists_url":"https://api.github.com/users/Master-Inspire/gists{/gist_id}","starred_url":"https://api.github.com/users/Master-Inspire/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Master-Inspire/subscriptions","organizations_url":"https://api.github.com/users/Master-Inspire/orgs","repos_url":"https://api.github.com/users/Master-Inspire/repos","events_url":"https://api.github.com/users/Master-Inspire/events{/privacy}","received_events_url":"https://api.github.com/users/Master-Inspire/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/NLog/NLog/labels/discussion","name":"discussion","color":"006b75"},{"url":"https://api.github.com/repos/NLog/NLog/labels/target","name":"target","color":"ffffff"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-09-08T15:52:41Z","updated_at":"2016-09-16T08:02:16Z","closed_at":null,"body":"# Incorrect urlencode of WebService target\r\n**Type**:Bug\r\n**NLog version**: 4.3.8\r\n**Platform**: .Net 4.6\r\n**Current NLog config**\r\n```xml\r\n<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n<nlog xmlns=\"http://www.nlog-project.org/schemas/NLog.xsd\"\r\n      xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n      xsi:schemaLocation=\"http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd\"\r\n      autoReload=\"true\"\r\n      throwExceptions=\"false\"\r\n      internalLogLevel=\"Off\" internalLogFile=\"c:\\temp\\nlog-internal.log\">\r\n    <targets>\r\n        <target xsi:type='WebService'\r\n                name='ws'\r\n                url='http://localhost:3333/api/logme'\r\n                protocol='HttpPost'\r\n                encoding='UTF-8'   >\r\n            <parameter name='param1' type='System.String' layout='${message}'/>\r\n            <parameter name='param2' type='System.String' layout='${logger}'/>\r\n        </target>\r\n    </targets>\r\n    <rules>\r\n        <logger name='*' writeTo='ws'></logger>\r\n    </rules>\r\n</nlog>\r\n```\r\n**Api Controller**\r\n```csharp\r\npublic class LogMeController: ApiController {\r\n    /// <summary>\r\n    /// We need a complex type for modelbinding because\r\n    /// of content-type: \"application/x-www-form-urlencoded\"\r\n    /// </summary>\r\n    public class ComplexType {\r\n        public string Param1 { get; set; }\r\n        public string Param2 { get; set; }\r\n    }\r\n\r\n    public void Post([FromBody] ComplexType complexType) {\r\n        Console.WriteLine(complexType);\r\n    }\r\n}\r\n```\r\nJust use the [WebService target](https://github.com/NLog/NLog/wiki/WebService-target) as an example.\r\n**Controller, write some special characters**\r\n```csharp\r\npublic class SimpleController: Controller {\r\n    private static readonly ILogger _logger = LogManager.GetCurrentClassLogger();\r\n\r\n    public ActionResult Index() {\r\n        _logger.Error(\"《∠∠⊙⌒∈∽》`````\");\r\n        return new ContentResult() {\r\n            Content = \"Simple\"\r\n        };\r\n    }\r\n}\r\n```\r\n**And result**\r\n![1](https://cloud.githubusercontent.com/assets/9047578/18355795/dc011dee-761c-11e6-905f-ac4eb35991de.png)\r\n**NLog's source _src\\NLog\\Targets\\WebServiceTarget.cs_ at line 375**\r\n```csharp\r\nforeach (MethodCallParameter parameter in this.Parameters)\r\n{\r\n    sw.Write(separator);\r\n    sw.Write(parameter.Name);\r\n    sw.Write(\"=\");\r\n    sw.Write(UrlHelper.UrlEncode(Convert.ToString(parameterValues[i], CultureInfo.InvariantCulture), true));\r\n    separator = \"&\";\r\n    i++;\r\n}\r\n```\r\nIf I change the `UrlHelper.UrlEncode` method to `System.Net.WebUtility.UrlEncode` method, then i can get the `Param1` correctly decoded. So I think the `UrlHelper.UrlEncode`  may not correct. \r\n\r\n`UrlHelper.UrlEncode` and `System.Net.WebUtility.UrlEncode` is different.\r\n```csharp\r\n[TestFixture]\r\npublic class MyClass {\r\n    [Test]\r\n    public void TestMethod1() {\r\n        var encode1 = UrlHelper.UrlEncode(\"《∠∠⊙⌒∈∽》`````\", true);\r\n        Console.WriteLine(encode1);\r\n        // %u300a%u2220%u2220%u2299%u2312%u2208%u223d%u300b%60%60%60%60%60\r\n        var encode2 = System.Net.WebUtility.UrlEncode(\"《∠∠⊙⌒∈∽》`````\");\r\n        Console.WriteLine(encode2);\r\n        // %E3%80%8A%E2%88%A0%E2%88%A0%E2%8A%99%E2%8C%92%E2%88%88%E2%88%BD%E3%80%8B%60%60%60%60%60\r\n    }\r\n}\r\n```\r\n`System.Net.WebUtility.UrlDecode` can not decode the string from `UrlHelper.UrlEncode`."},"comment":{"url":"https://api.github.com/repos/NLog/NLog/issues/comments/247541692","html_url":"https://github.com/NLog/NLog/issues/1629#issuecomment-247541692","issue_url":"https://api.github.com/repos/NLog/NLog/issues/1629","id":247541692,"user":{"login":"304NotModified","id":5808377,"avatar_url":"https://avatars.githubusercontent.com/u/5808377?v=3","gravatar_id":"","url":"https://api.github.com/users/304NotModified","html_url":"https://github.com/304NotModified","followers_url":"https://api.github.com/users/304NotModified/followers","following_url":"https://api.github.com/users/304NotModified/following{/other_user}","gists_url":"https://api.github.com/users/304NotModified/gists{/gist_id}","starred_url":"https://api.github.com/users/304NotModified/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/304NotModified/subscriptions","organizations_url":"https://api.github.com/users/304NotModified/orgs","repos_url":"https://api.github.com/users/304NotModified/repos","events_url":"https://api.github.com/users/304NotModified/events{/privacy}","received_events_url":"https://api.github.com/users/304NotModified/received_events","type":"User","site_admin":false},"created_at":"2016-09-16T08:02:16Z","updated_at":"2016-09-16T08:02:16Z","body":"Any idea if there are any RFCs for URL encode? It difficult that there are multiple implementations and unclear specs"}}
{"actor":{"display_login":"304NotModified"}}