开发者社区> 问答> 正文

阿里云日志上报系统,c#版本,_addInternalMethod 引用 永远为空

_addInternalMethod这个引用永远为空,原因就是.net40里WebHeaderCollection这里根本没有AddInternal这个函数,我用的是阿里云日志上报系统,SLSSDK40,C#版本,WIN10控制台程序

internal static void AddInternal(this WebHeaderCollection headers, string key, string value) { if (isMonoPlatform == null) { isMonoPlatform = monoPlatforms.Contains(System.Environment.OSVersion.Platform); }

        // HTTP headers should be encoded to iso-8859-1,
        // however it will be encoded automatically by HttpWebRequest in mono.
        if (isMonoPlatform == false)
            // Encode headers for win platforms.
            value = HttpUtils.ReEncode(
                value,
                HttpUtils.UTF8Charset,
                HttpUtils.Iso88591Charset);

        if (_addInternalMethod == null)
        {
            // Specify the internal method name for adding headers
            // mono: AddWithoutValidate
            // win: AddInternal
            string internalMethodName = (isMonoPlatform == true) ? "AddWithoutValidate" : "AddInternal";
            //string internalMethodName = "AddWithoutValidate";

            MethodInfo mi = typeof(WebHeaderCollection).GetMethod(
                internalMethodName,
                BindingFlags.NonPublic | BindingFlags.Instance,
                null,
                new Type[] { typeof(string), typeof(string) },
                null);
            _addInternalMethod = mi;
        }

        _addInternalMethod.Invoke(headers, new object[] { key, value });
    }

展开
收起
游客mva3we5zthdiu 2020-03-25 10:27:12 736 0
1 条回答
写回答
取消 提交回答
  • 兄弟那你怎么处理的呢?

    2023-06-30 10:14:26
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
阿里云云原生Serverless产品手册 立即下载
阿里云认证的解析与实战-云计算ACP认证 立即下载
阿里云认证的解析与实战-数据仓库ACP认证 立即下载