2

I need to send an image(jpeg,png,etc) to server with parameter "access_token" and "photo"(image that I need to send).

..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

2 Answers 2

1

You cannot "GET" an image to a URL (you are trying to post data into the URL which you can't), you need to "POST" your image using the OutputStream of your POST request.

Sign up to request clarification or add additional context in comments.

8 Comments

Well, you can, but it has to be encoded in a query string parameter or cookie. (Cookies can be generated client-side).
yes but I think they have a size limit (e.g. 8K or something), which is not suitable (and not intended) for sending images, but yes technically it IS possible
function "get_data" is making post request.The server supports receiving images.How I can do it(like you say) with OutputStream ?
well, you shouldn't be writing to the URL query string so first delete that part (to avoid further confusion). second, I don't know which library this you are using.. it's not the standard web client of .NET framework... is it facebook or something?
I'm using API of site like facebook, not facebook. I need to send an image(jpg,png,gif) to the server like "server_url?photo=my_photo&access_token=key".
|
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();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.