如何看待微信公开课小程序热门讨论「小程序,获取OpenID失败」
摘要:小程序,获取OpenID失败
展开:在小程序里面获得Code后,传到服务端进一步获取OpenID,但报告Unabletoconnecttotheremoteserver错误。C代码如下:stringstrUrlStringhttps://api.weixin.qq.com/sns/jscode2session?appid{0}secret{1}js_code{2}grant_typeauthorization_code;stringurlstring.Format(strUrlString,strAppID_Xiao,strAppSecret_Xiao,code);GetUsersHelperGetUsersHelpernewGetUsersHelper();stringRequestObjGetUsersHelper.WXWebRequest(url,string.Empty);……WXWebRequest方法代码如下:publicstringWXWebRequest(stringposturl,stringpostData){Streamoutstreamnull;Streaminstreamnull;StreamReadersrnull;HttpWebResponseresponsenull;HttpWebRequestrequestnull;EncodingencodingEncoding.UTF8;LoglognewLog(AppDomain.CurrentDomain.BaseDirectory+@/log/Log.txt);byte[]dataencoding.GetBytes(postData);//准备请求try{//设置参数requestWebRequest.Create(posturl)asHttpWebRequest;CookieContainercookieContainernewCookieContainer();request.CookieContainercookieContainer;request.AllowAutoRedirecttrue;request.MethodPOST;request.ContentTypeapplication/xwwwformurlencoded;request.ContentLengthdata.Length;outstreamrequest.GetRequestStream();outstream.Write(data,0,data.Length);outstream.Close();System.Net.ServicePointManager.DefaultConnectionLimit50;//发送请求并获取相应回应数据responserequest.GetResponse()asHttpWebResponse;//直到request.GetResponse()程序才开始向目标网页发送Post请求instreamresponse.GetResponseStream();srnewStreamReader(instream,encoding);//返回结果网页(html)代码stringcontentsr.ReadToEnd();stringerrstring.Empty;response.Close();responsenull;requestnull;returncontent;}catch(Exceptionex){log.WriteLog(/WXWebRequest出现错误,错误信息如下:/);log.WriteLog(Class:+ex.TargetSite.DeclaringType.Name);log.WriteLog(Method:+ex.TargetSite.Name);log.WriteLog(ErrorMessage:+ex.Message);log.WriteLog(//);returnstring.Empty;}}服务器的IP已经添加到小程序绑定的那个公众号的IP白名单中去了。请教问题出在哪里了解更多