【问题标题】:Silverlight 4, Google Chrome, and HttpWebRequest problemSilverlight 4、Google Chrome 和 HttpWebRequest 问题
【发布时间】:2010-06-15 14:59:02
【问题描述】:

托管在 ASP.NET MVC 2 中的我的 Silvrlight 4 应用程序在通过 Internet Explorer 8 使用时工作正常,无论是在开发服务器还是远程 Web 服务器 (IIS 6.0) 中。但是,当我尝试浏览 Google Chrome(版本 5.0.375.70)时,它会抛出“未找到远程服务器返回”错误。导致问题的代码如下:

public class MyWebClient
{
  private HttpWebRequest _request;
  private Uri _uri;
  private AsyncOperation _asyncOp;

  public MyWebClient(Uri uri)
  { 
    _uri = uri; 
  }

  public void Start(XElement data)
  {
    _asyncOp = AsyncOperationManager.CreateOperation(null);
    _data = data;
    _request = (HttpWebRequest)WebRequest.Create(_uri);
    _request.Method = "POST";
    _request.BeginGetRequestStream(new AsyncCallback(BeginRequest), null);
  }

  private void BeginRequest(IAsyncResult result)
  {
    Stream stream = _request.EndGetRequestStream(result);
    using (StreamWriter writer = new StreamWriter(stream))
    {
      writer.Write(((XElement)_data).ToString());
    }
    stream.Close();
    _request.BeginGetResponse(new AsyncCallback(BeginResponse), null);
  }

  private void BeginResponse(IAsyncResult result)
  {
    HttpWebResponse response = (HttpWebResponse)_request.EndGetResponse(result);
    if (response != null)
    {
       //process returned data
        ...
    }
  }
  ...
 }

简而言之,上面的代码将一些 XML 数据发送到 Web 服务器(到 ASP.NET MVC 控制器)并取回处理后的数据。当我使用 Internet Explorer 8 时它可以工作。有人可以解释一下 Google Chrome 有什么问题吗?

【问题讨论】:

  • 您是否查看过 IIS 日志以检查来自 Chrome 的 URI 和参数是否正确? IE 有自动对 HTML 参数进行编码的习惯。我不知道 Chrome 是否会这样做(Firefox 不会)。
  • 我检查了日志文件:Chrome:2010-06-15 01:45:39 W3SVC1452470319 10.1.1.22 POST /AppServices/ProcessData - 80 - 10.1.12.74 Mozilla/5.0+(Windows;+U; +Windows+NT+5.1;+en-US)+AppleWebKit/533.4+(KHTML,+like+Gecko)+Chrome/5.0.375.70+Safari/533.4 500 0 0 IE: 2010-06-15 01:48:14 W3SVC1452470319 10.1.1.22 POST /AppServices/ProcessData - 80 - 10.1.12.74 Mozilla/4.0+(兼容;+MSIE+7.0;+Windows+NT+5.1;+Trident/4.0;+.NET+CLR+2.0.50727;+ .NET+CLR+3.0.4506.2152;+.NET+CLR+3.5.30729;+.NET4.0C;+.NET4.0E) 200 0 0 有什么提示吗?

标签: asp.net-mvc-2 google-chrome httpwebrequest silverlight-4.0


【解决方案1】:

我发现问题与使用 Google Chrome 处理 ASP.NET MVC 路由有关,因此提出了一个新问题:

ASP.NET MVC routing issue with Google Chrome client

【讨论】:

    猜你喜欢
    • 2012-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多