2011-08-13 22 views
2

我需要發送一個圖像(JPEG,PNG等)到服務器與參數「access_token」和「照片」(我需要發送的圖像)。發送圖片在WP7

..if (e.TaskResult == TaskResult.OK) { 
       BitmapImage image = new BitmapImage(); 
       image.SetSource(e.ChosenPhoto); 
       // foto.Source = image; 
       Byte[] byteArray; 
       using (MemoryStream ms = new MemoryStream()) { 
        WriteableBitmap btmMap = new WriteableBitmap(image); 

        // write an image into the stream 
        System.Windows.Media.Imaging.Extensions.SaveJpeg(btmMap, ms, image.PixelWidth, image.PixelHeight, 0, 100); 

        byteArray = ms.ToArray(); 
       } 
((App)Application.Current).get_data(uploadServer + "?photo=" + *HOW I CAN SEND BYTE ARRAY?* + "&access_token=" + ((App)Application.Current).access_token 

//

public void get_data(string url,Action<string> qw) { 
      try { 
       var request = (HttpWebRequest)WebRequest.Create(
        new Uri(url)); 
       request.BeginGetResponse(r => { 
        var httpRequest = (HttpWebRequest)r.AsyncState; 
        var httpResponse = (HttpWebResponse)httpRequest.EndGetResponse(r); 
        HttpStatusCode st = httpResponse.StatusCode; 
        if (st == HttpStatusCode.NotFound) { 
         ToastPrompt toast = new ToastPrompt(); 
         toast.TextOrientation = System.Windows.Controls.Orientation.Vertical; 
         toast.Message = "Ошибка соединения с сервером"; 
         toast.MillisecondsUntilHidden = 2000; 
         toast.Show(); 
        } else 
         using (var reader = new StreamReader(httpResponse.GetResponseStream())) { 
          var response = reader.ReadToEnd(); 
          Deployment.Current.Dispatcher.BeginInvoke(new Action(() => { 
           qw(response); 
          })); 

         } 
       }, request); 
      } catch (WebException e) { } 
     } 
+0

UPD:沒有ACCESS_TOKEN需要。 – SevenDays

回答

0

WP7 - POST form with an image

Dictionary<string, object> data = new Dictionary<string, object>() 
        { 
        {"photo", byteArray}, 
        }; 
        PostSubmitter post = new PostSubmitter() { url = uploadServer, parameters = data }; 
        post.Submit(); 
1

你不能 「GET」 到URL的圖像(您要發佈數據到URL您可以沒有哪個),你需要「POST 「您的圖片使用您的POST請求的OutputStream

+0

那麼,你*可以*,但它必須被編碼在查詢字符串參數或cookie中。 (Cookies可以在客戶端生成)。 –

+0

是的,但我認爲他們有一個大小限制(例如8K或者其他),這是不適合(而不是打算)發送圖像,但是從技術上說可能 –

+0

功能「get_data」發出post request.The服務器支持接收images.How我可以做到這一點(就像你說的)與OutputStream? – SevenDays