2011-07-26 26 views
0

私はそれらのような2つの同じリンクをロードするとき a linkhttp://files.sparklingclient.com/099_2010.07.09_WP7_Phones_In_The_Wild.mp3 これらはすべてIEでダウンロードすることができますが、wp7でダウンロードした場合、最初のエラーをダウンロードすることができます。 ""リモートサーバーからエラーが返されました:NotFound。 "" .is webURL wp7には適していませんか?mp3をダウンロードしようとすると、エラーが発生しました。「リモートサーバーがエラーを返しました:NotFound」

private void Button_Click(object sender, RoutedEventArgs e) 
{ 
    stringUri = "http://upload16.music.qzone.soso.com/30828161.mp3"; 
    //stringUri = "http://files.sparklingclient.com/079_2009.08.20_ElementBinding.mp3"; 
    Uri uri = new Uri(stringUri, UriKind.Absolute);    
    GetMusic(uri); 
} 
private void GetMusic(Uri uri) 
{ 
    request = WebRequest.Create(uri) as HttpWebRequest; 
    request.Method = "Post"; 
    request.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";    
    string header= request.Accept; 
    request.BeginGetResponse(new AsyncCallback(GetAsynResult),request); 

} 
void GetAsynResult(IAsyncResult result) 
{   

    HttpWebResponse reponse = request.EndGetResponse(result) as HttpWebResponse; 
    if (reponse.StatusCode == HttpStatusCode.OK) 
    { 

     Stream stream=reponse.GetResponseStream(); 
     SaveMusic(stream, "music"); 
     ReadMusic("music"); 
     Deployment.Current.Dispatcher.BeginInvoke(
      () => 
      { 
       me.AutoPlay = true; 
       me.Volume = 100; 
       songStream.Position = 0; 
       me.SetSource(songStream); 
       me.Play(); 
      }); 

    }   
} 
protected void SaveMusic(Stream stream,string name) 
{ 

      IsolatedStorageFile fileStorage = IsolatedStorageFile.GetUserStoreForApplication(); 
      if (!fileStorage.DirectoryExists("Source/Music")) 
      { 
       fileStorage.CreateDirectory("Source/Music"); 
      } 
      using (IsolatedStorageFileStream fileStream = IsolatedStorageFile.GetUserStoreForApplication().OpenFile("Source\\Music\\" + name + ".mp3", FileMode.Create)) 
      { 
       byte[] bytes = new byte[stream.Length]; 
       stream.Read(bytes, 0, bytes.Length); 
       fileStream.Write(bytes, 0, bytes.Length); 
       fileStream.Flush(); 
      } 

} 
protected void ReadMusic(string name) 
{ 

     using (IsolatedStorageFile fileStorage = IsolatedStorageFile.GetUserStoreForApplication()) 
     { 
      songStream = null; 
      songStream = new IsolatedStorageFileStream("Source\\Music\\" + name + ".mp3", FileMode.Open, fileStorage);     

     } 

} 
+0

あなたの質問にはGoogle翻訳の使用を中止する必要があります。 –

+0

yorのアドバイスありがとう、次回は私はビン翻訳を使用します;またはあなたが私を助けることができます –

答えて

1

あなたがFiddlerを実行しようとしている、あなたはエミュレータ上で、この問題に実行している場合は

request.Method = "Get" 
+0

+1よく見つかった!しかし、実際には互換性のために 'GET'(大文字)にする必要があります。 –

0

request.Method = "Post" 

を変更してみてください?それはHTTPリクエストを傍受し、サーバーに行われている呼び出しが期待どおりのものかどうかを確認できます。

Fiddlerを起動した後、エミュレータを閉じて再起動して、プロキシを受け取るようにしてください。

NotFound応答が不正なSSL証明書でも発生する可能性があります。それはあなたの問題に関連するようには見えませんが、心に留めておいてください。

関連する問題