收藏
回答

获取手机号码时提交到C#后台错误怎么解决?

接收的参数

  string encryptedData = Request.QueryString["encryptedData"];

   string iv = Request.QueryString["iv"];

string session_key = Request.QueryString["session_key"];

接收到了出错。怎么解决这个呢?

下面是提交过去的参数,

-------------------------------------------------------------

encryptedData: "Tx6KCFvYbdoZ01C19SHXsVemO155JoQmaeJaaaTX5EZkM1lK5UrD3NBrC/6HkZEpC4Jcfw8s5guWcrFB1P+dJ2JEGvo6WI939K7R+vmUxsQRwadChrE3d1yveGcCP6f6A88tHnPq407Chw2h/8ZrZJC7O5gZm/pxbQT33t2yHmpkuboHm7wrl897ZH44ocx2NsD13T4p3I5tAyODUXXHfA=="

iv: "N4jC6bfGPkRUMOA5WNl3AQ=="

session_key: "QNNuDoOyWFBqB5E\/zt0Eqw=="

--------------------------------------------------------

以下出错:

"<!DOCTYPE html>

<html>

    <head>

        <title>输入的不是有效的 Base-64 字符串,因为它包含非 Base-64 字符、两个以上的填充字符,或者填充字符间包含非法字符。</title>

        <meta name="viewport" content="width=device-width" />

        <style>

         body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} 

         p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}

         b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}

         H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }

         H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }

         pre {font-family:"Consolas","Lucida Console",Monospace;font-size:11pt;margin:0;padding:0.5em;line-height:14pt}

         .marker {font-weight: bold; color: black;text-decoration: none;}

         .version {color: gray;}

         .error {margin-bottom: 10px;}

         .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:pointer; }

         @media screen and (max-width: 639px) {

          pre { width: 440px; overflow: auto; white-space: pre-wrap; word-wrap: break-word; }

         }

         @media screen and (max-width: 479px) {

          pre { width: 280px; }

         }

        </style>

    </head>


    <body bgcolor="white">


            <span><H1>“/”应用程序中的服务器错误。<hr width=100% size=1 color=silver></H1>


            <h2> <i>输入的不是有效的 Base-64 字符串,因为它包含非 Base-64 字符、两个以上的填充字符,或者填充字符间包含非法字符。</i> </h2></span>


            <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">


            <b> 说明: </b>执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。


            <br><br>


            <b> 异常详细信息: </b>System.FormatException: 输入的不是有效的 Base-64 字符串,因为它包含非 Base-64 字符、两个以上的填充字符,或者填充字符间包含非法字符。<br><br>


            <b>源错误:</b> <br><br>


            <table width=100% bgcolor="#ffffcc">

               <tr>

                  <td>

                      <code><pre>


行 242:            byte[] encryData = Convert.FromBase64String(encryptedData);

行 243:            RijndaelManaged rijndaelCipher = new RijndaelManaged();

<font color=red>行 244:            rijndaelCipher.Key = Convert.FromBase64String(session_key);

</font>行 245:            rijndaelCipher.IV = Convert.FromBase64String(iv);

行 246:            rijndaelCipher.Mode = CipherMode.CBC;</pre>                      </code>


                  </td>

               </tr>

            </table>


            <br>


            <b> 源文件: </b> E:\sysXiaoshou\sysXiaoshou\wxapi\getuserinfo.aspx.cs<b> &nbsp;&nbsp; 行: </b> 244

            <br><br>


            <b>堆栈跟踪:</b> <br><br>


            <table width=100% bgcolor="#ffffcc">

               <tr>

                  <td>

                      <code><pre>


[FormatException: 输入的不是有效的 Base-64 字符串,因为它包含非 Base-64 字符、两个以上的填充字符,或者填充字符间包含非法字符。]

   System.Convert.FromBase64_Decode(Char* startInputPtr, Int32 inputLength, Byte* startDestPtr, Int32 destLength) +6226339

   System.Convert.FromBase64CharPtr(Char* inputPtr, Int32 inputLength) +147

   System.Convert.FromBase64String(String s) +50

   sysXiaoshou.wxapi.getuserinfo.getphone_data() in E:\sysXiaoshou\sysXiaoshou\wxapi\getuserinfo.aspx.cs:244

   sysXiaoshou.wxapi.getuserinfo.Page_Load(Object sender, EventArgs e) in E:\sysXiaoshou\sysXiaoshou\wxapi\getuserinfo.aspx.cs:35

   System.Web.UI.Control.OnLoad(EventArgs e) +108

   System.Web.UI.Control.LoadRecursive() +90

   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1602

</pre>                      </code>


                  </td>

               </tr>

            </table>


            <br>


            <hr width=100% size=1 color=silver>


            <b>版本信息:</b>&nbsp;Microsoft .NET Framework 版本:4.0.30319; ASP.NET 版本:4.8.9206.0


            </font>


    </body>

</html>

<!-- 

[FormatException]: 输入的不是有效的 Base-64 字符串,因为它包含非 Base-64 字符、两个以上的填充字符,或者填充字符间包含非法字符。

   在 System.Convert.FromBase64_Decode(Char* startInputPtr, Int32 inputLength, Byte* startDestPtr, Int32 destLength)

   在 System.Convert.FromBase64CharPtr(Char* inputPtr, Int32 inputLength)

   在 System.Convert.FromBase64String(String s)

   在 sysXiaoshou.wxapi.getuserinfo.getphone_data() 位置 E:\sysXiaoshou\sysXiaoshou\wxapi\getuserinfo.aspx.cs:行号 244

   在 sysXiaoshou.wxapi.getuserinfo.Page_Load(Object sender, EventArgs e) 位置 E:\sysXiaoshou\sysXiaoshou\wxapi\getuserinfo.aspx.cs:行号 35

   在 System.Web.UI.Control.OnLoad(EventArgs e)

   在 System.Web.UI.Control.LoadRecursive()

   在 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

[HttpUnhandledException]: 引发类型为“System.Web.HttpUnhandledException”的异常。

   在 System.Web.UI.Page.HandleError(Exception e)

   在 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

   在 System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

   在 System.Web.UI.Page.ProcessRequest()

   在 System.Web.UI.Page.ProcessRequest(HttpContext context)

   在 ASP.wxapi_getuserinfo_aspx.ProcessRequest(HttpContext context) 位置 c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\822d7d9d\393e6636\App_Web_2ojkjvay.1.cs:行号 0

   在 System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()

   在 System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)

   在 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

-->"

回答关注问题邀请回答
收藏

2 个回答

  • NoBug
    NoBug
    01-05

    01-05
    有用
    回复
  • 正青春
    正青春
    01-04
     string code = context.Request.Params["code"].ToString();
                string access_token = context.Request.Params["access_token"].ToString();
                context.Response.ContentEncoding = Encoding.UTF8;
    
    
                string url = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=" + access_token;
                
                Hashtable hashtable = new Hashtable();
                hashtable.Add("code", code);
                string postSet = JsonConvert.SerializeObject(hashtable);
                byte[] by = Encoding.UTF8.GetBytes(postSet);//参数编码
                HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
                
                httpWebRequest.Method = "POST";
                httpWebRequest.ContentLength = by.Length;
                httpWebRequest.ContentType = "application/json";//链接类型
    
    
                //发送post的请求,写入参数
                Stream write = httpWebRequest.GetRequestStream();
                write.Write(by,0,by.Length);
                write.Close();
    
    
                //接受返回来的数据
                HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                Stream sreamResponse = httpWebResponse.GetResponseStream();
                StreamReader streamReader = new StreamReader(sreamResponse, Encoding.UTF8);
                string result = streamReader.ReadToEnd().Trim();
    
                streamReader.Close();
                sreamResponse.Close();
                httpWebResponse.Close();
                JObject phone_data = JObject.Parse(result);
                string phoneInfo = phone_data["phone_info"].ToString();
    
                JObject phone = JObject.Parse(phoneInfo);
                string phoneNum = phone["phoneNumber"].ToString();
    
    01-04
    有用
    回复 3
    • 古道儒风
      古道儒风
      发表于移动端
      01-05
      access_token 只提交这个过去就可以获取手机了吗?
      01-05
      回复
    • 正青春
      正青春
      01-05回复古道儒风
      code也要获取啊
      01-05
      回复
    • 古道儒风
      古道儒风
      发表于移动端
      01-05回复正青春
      好像去掉斜杠就对了
      01-05
      回复
登录 后发表内容