码迷,mamicode.com
首页 > 微信 > 详细

微信公众号禁止设置ngrok地址的解决办法

时间:2016-06-20 15:38:55      阅读:4025      评论:0      收藏:0      [点我收藏+]

标签:

最近想改一下以前测试公众号的地址为ngrok2的亚洲节点,结果提示安全问题,禁止设置。原来是微信把类似花生壳ngrok等这些地址都封了。

现在暂时用的解决办法是在外网服务器上做一个转发程序,只需一个handler

using System.Configuration;
using System.Diagnostics;
using System.Net;
using System.Web;

namespace WechatProxy
{
    public class WechatHandler : IHttpHandler
    {
        private TraceSource trace;
        public WechatHandler()
        {
            IsReusable = true;
            trace = new TraceSource("trace");
        }
        public void ProcessRequest(HttpContext context)
        {

            var url = string.Format("http://{0}{1}{2}", ConfigurationManager.AppSettings["host"],
                context.Request.Path,
                context.Request.QueryString.Count > 0 ? ("?" + context.Request.QueryString) : "");
            trace.TraceInformation(url);
            var request = WebRequest.Create(url);
            if (context.Request.RequestType == "POST")
            {
                request.Method = "POST";
                using (var reqstream = request.GetRequestStream())
                {
                    context.Request.InputStream.CopyTo(reqstream);
                }
            }
            var response = request.GetResponse();
            using (var resstream = response.GetResponseStream())
            {
                resstream.CopyTo(context.Response.OutputStream);
            }
        }

        public bool IsReusable { get; private set; }
    }
}
<?xml version="1.0" encoding="utf-8"?>

<configuration>
  <appSettings>
    <add key="host" value="xxxx.ap.ngrok.io" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <httpHandlers>
      <clear />
      <add type="WechatProxy.WechatHandler" path="*" verb="GET,POST" />
    </httpHandlers>
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>
  <system.diagnostics>
    <sources>
      <source name="trace" switchName="SourceSwitch" switchType="System.Diagnostics.SourceSwitch">
        <listeners>
          <clear/>
          <add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="WechatProxy" />
        </listeners>
      </source>
    </sources>
    <switches>
      <add name="SourceSwitch" value="Verbose"/>
      <!--add name="SourceSwitch" value="Off Verbose Information Warning Error Critical All" -->
    </switches>
    <trace autoflush="true" indentsize="4"/>
  </system.diagnostics>
</configuration>

 

微信公众号禁止设置ngrok地址的解决办法

标签:

原文地址:http://www.cnblogs.com/ly303550688/p/5600560.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!