Reputation: 3768
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) { }
}
Upvotes: 2
Views: 825
Reputation: 3768
Dictionary<string, object> data = new Dictionary<string, object>()
{
{"photo", byteArray},
};
PostSubmitter post = new PostSubmitter() { url = uploadServer, parameters = data };
post.Submit();
Upvotes: 0
Reputation: 34830
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.
Upvotes: 1