繁体   English   中英

WP7(Windows Phone 7)和Fiddler的HTTP流传输问题

[英]HTTP Streaming issues with WP7 (Windows Phone 7) and Fiddler

我为WP7开发的程序存在一个非常特殊的问题。 首先,我正在开发一个异步使用HttpWebRequest / Response的流报价应用程序。 我还在Fiddler中监视整个过程,以确保一切正确。

引号通过与服务器的始终开放的Http连接进入。 登录正常,以及提交报价订阅请求。 问题是,除非执行以下两项操作之一,否则我永远都不会收到响应(它永远不会到达EndGetResponse):

1-通过Fiddler重新发出开放订阅请求2-通过Fiddler的RequestBuilder提交相同的请求

我试图在笔记本电脑上的模拟器上运行此应用程序,但该应用程序无法正常工作,我遇到了协议异常,但这是另一个线程的问题。

有任何想法吗? 我认为这与通过Fiddler传输数据有关。 我尝试卸载Fiddler,禁用捕获,撤消WinInet中的代理设置,但没有任何效果。 这让我发疯,所以您的帮助将不胜感激。

更新:我能够使用Twitter的流API重新创建它。 下面是新代码。 只需使用自己的凭据更改占位符:

MainPage.xaml:

<phoneNavigation:PhoneApplicationPage 
    x:Class="TestHttpStreaming.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phoneNavigation="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Navigation"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="800"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}">

    <Grid x:Name="LayoutRoot" Background="{StaticResource PhoneBackgroundBrush}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--TitleGrid is the name of the application and page title-->
        <Grid x:Name="TitleGrid" Grid.Row="0">
            <TextBlock Text="MY APPLICATION" x:Name="textBlockPageTitle" Style="{StaticResource PhoneTextPageTitle1Style}"/>
            <TextBlock Text="page title" x:Name="textBlockListTitle" Style="{StaticResource PhoneTextPageTitle2Style}"/>
        </Grid>

        <!--ContentGrid is empty. Place new content here-->
        <Grid x:Name="ContentGrid" Grid.Row="1">
            <Button Content="Test" Height="70" HorizontalAlignment="Left" Margin="163,149,0,0" Name="button1" VerticalAlignment="Top" Width="160" Click="button1_Click" />
        </Grid>
    </Grid>

</phoneNavigation:PhoneApplicationPage>

MainPage.xaml.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO;

namespace TestHttpStreaming
{
    public partial class MainPage : PhoneApplicationPage
    {
        public MainPage()
        {
            InitializeComponent();

            SupportedOrientations = SupportedPageOrientation.Portrait | SupportedPageOrientation.Landscape;
        }

        Uri uri = null;
        HttpWebRequest request = null;
        byte[] buffer = new byte[1024];
        Stream stream = null;
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            uri = new Uri("http://stream.twitter.com/1/statuses/sample.json?delimited=length", UriKind.Absolute);
            request = (HttpWebRequest)WebRequest.Create(uri);
            request.Method = "GET";
            request.Credentials = new NetworkCredential("[username]", "[password]");
            request.BeginGetResponse(new AsyncCallback(this.EndGetResponseStream), null);
        }
        void EndGetResponseStream(IAsyncResult result)
        {
            try
            {
                HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result);
                stream = response.GetResponseStream();
                IAsyncResult iarRead = stream.BeginRead(buffer, 0, 1024, new AsyncCallback(StreamingReadCallBack), null);
            }
            finally
            {
            }
        }
        private void StreamingReadCallBack(IAsyncResult asyncResult)
        {
            int read = stream.EndRead(asyncResult);
        }
    }
}

不知道是否有人仍然面临这个问题。 我遇到了这个问题,并在设置后得到修复:

request.AllowReadStreamBuffering = false;

这是最新的框架。

请检查以查看:

  1. 您是否在工具条菜单栏上启用了流模式?

    2.是否关闭了“启用自动回复”?

希望对您有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM