0

WP7 で完全に動作する以前のアプリが WP8 で動作しないという問題があります。

これは、http 要求に使用しているコードです。

public void SendMessage()
    {    
        request = WebRequest.Create(uri) as HttpWebRequest;
        request.Method = "POST";
        request.AllowReadStreamBuffering = true;
        request.ContentType = "application/octet-stream";

        try 
        {
            // get device info
            String deviceInfo = String.Format("platform,{0};os,{1};width,{2};height,{3};dpi,{4};",
                Config.PLATFORM_NAME,
                Environment.OSVersion.Version.ToString(),
                System.Windows.Application.Current.Host.Content.ActualWidth.ToString(),
                System.Windows.Application.Current.Host.Content.ActualHeight.ToString(),
                96);
            request.Headers["X_MX_DEVICE_INFO"] = deviceInfo;
        } 
        catch (Exception) {}

        request.BeginGetRequestStream(new AsyncCallback(ProcessRequestStream), null);
    }

    private void ProcessRequestStream(IAsyncResult asyncResult)
    {
        if (!message.IsCancelled())
        {
            try
            {
                using (Stream stream = request.EndGetRequestStream(asyncResult))
                {
                    message.GetRequest(stream);
                }
                request.BeginGetResponse(new AsyncCallback(ProcessResponseStream), null);
            }
            catch (Exception e)
            {
                syncContext.Post(OnEnd, e);
            }
        }
        else
        {
            syncContext.Post(OnEnd, null);
        }
    }

    private void ProcessResponseStream(IAsyncResult asyncResult)
    {
        if (!message.IsCancelled())
        {
            try
            {
                response = (HttpWebResponse)request.EndGetResponse(asyncResult);
                if (HttpStatusCode.OK != response.StatusCode)
                {
                    throw new Exception("http status error: " + response.ToString());
                }

                syncContext.Post(SetResponse, response);
            }
            catch (Exception e)
            {
                syncContext.Post(OnEnd, e);
            }
        }
        else
        {
            syncContext.Post(OnEnd, null);
        }
    }

    private void SetResponse(object state)
    {
        Exception ex = null;
        try
        {
            using (Stream stream = ((HttpWebResponse)state).GetResponseStream())
            {
                message.SetRespone(stream);
            }
        }
        catch (Exception e)
        {
            ex = e;
        }
        syncContext.Post(OnEnd, ex);
    }

    private void OnEnd(object state)
    {
        message.OnEnd((Exception)state);
    }
}

BeginGetResponse のコールバックが起動されていないようです。私は Fiddler を試して、どのような応答が返されているかを確認しましたが、何も返されていないように見えますが、WP8 だけです。

これについて考えられる理由はありますか?

4

1 に答える 1

0

これは、Windows Phone 8 のリファラーの問題に関連している可能性があると思います。

WP7.1 の場合: Referer ヘッダーの値はデフォルトで null です。Referer ヘッダーのカスタム値を指定できます。

WP8 の場合: Referer ヘッダーの値は、アプリのインストール ディレクトリを file:///Applications/Install//Install/ の形式で参照します。

インターネット上にはいくつかのブログ投稿があり、可能な解決策があります。

しかし、あなたの場合でも、Fiddler のログを分析することを強くお勧めします。Fiddler4をダウンロードしてインストールしたことを確認します。また、最初にフィドラーを起動してから、WP エミュレーターを起動してください。

于 2013-03-27T15:32:08.403 に答える