在WP7中发送图像

时间:2011-08-13 00:54:29

标签: c# windows-phone-7 post httprequest

我需要使用参数“access_token”和“photo”(我需要发送的图像)向服务器发送图像(jpeg,png等)。

..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) { }
        }

2 个答案:

答案 0 :(得分:1)

您无法将图片“获取”为网址(您尝试将数据发布到您无法的网址中),您需要使用{{1“对您的图片进行”发布“您的POST请求。

答案 1 :(得分: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();