ASP.NET获取网页内容时出错

szjhxu 2016-12-08 02:56:07
环境:VS2010+VB2010

本地调试程序时完全正常,放在远程服务器上时就出现如下错误:


以前曾经能正常运行的。
找了找网上的解决方案,说是在web.config中加入

<system.net>
<settings>
<servicePointManager checkCertificateName="false" checkCertificateRevocationList="false" />
</settings>
</system.net>

我也加了,可是情况依然如旧,求高人解救!!!
...全文
221 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
szjhxu 2016-12-12
  • 打赏
  • 举报
回复
换一种方式写了页面: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Net; using System.Text.RegularExpressions; using System.Text; public partial class Default2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } public static string getHtml(string url, params string[] charSets) { try { string charSet = null; if (charSets.Length == 1) { charSet = charSets[0]; } WebClient myWebClient = new WebClient(); //创建WebClient实例myWebClient myWebClient.Credentials = CredentialCache.DefaultCredentials; byte[] myDataBuffer = myWebClient.DownloadData(url); string strWebData = Encoding.Default.GetString(myDataBuffer); //获取网页字符编码描述信息 Match charSetMatch = Regex.Match(strWebData, "<meta([^<]*)charset=([^<]*)", RegexOptions.IgnoreCase | RegexOptions.Multiline); string webCharSet = charSetMatch.Groups[2].Value; if (charSet == null || charSet == "") charSet = webCharSet; if (charSet != null && charSet != "" && Encoding.GetEncoding(charSet) != Encoding.Default) { strWebData = Encoding.GetEncoding(charSet).GetString(myDataBuffer); } else { strWebData = Encoding.GetEncoding("utf-8").GetString(myDataBuffer); } return strWebData; } catch (Exception e) { return ""; } } protected void Button1_Click(object sender, EventArgs e) { //Response.Write(getHtml("https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=wx6f952ddf4d761d06&corpsecret=Pm1rRxFph7ceeAZZIHuZts6lYkx8O_t0FsoK057WfB6tPI6VzON1nXeYpjeJClDC")); Response.Write(getHtml("https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=wx6f952ddf4d734506&corpsecret=gfjhguyfkjl867tuyhoi09hkjnoiui")); } } 在本地调试有返回结果,而放到远程服务器上,就什么都没有,也不出错。 疯了,要!!!
我2我骄傲 2016-12-09
  • 打赏
  • 举报
回复
把英文翻译成汉语是你需要的答案么?
我2我骄傲 2016-12-09
  • 打赏
  • 举报
回复
这样是看不出问题的。 只能知道 你请求的服务报错了。
弘毅致远 2016-12-09
  • 打赏
  • 举报
回复
认证没通过。
szjhxu 2016-12-09
  • 打赏
  • 举报
回复
本地环境:WIn7+VS2010 服务器环境:WIN2003+IIS6+.NET Frame 4

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧