Загрузить картинку на сайт - C#
Формулировка задачи:
Здравствуйте дорогие форумчани! С наступающим вас!!!)
У меня проблема следующего характера: надо загрузить фото на сайт.
вот что я имею после того как проснифер сайт:
Понятия не имею как произвести загрузку... наведите на путь истенный пжалуйста...
-----------------------------22798303036224 Content-Disposition: form-data; name="numero" 1 -----------------------------22798303036224 Content-Disposition: form-data; name="photoid[1]" photo_1 -----------------------------22798303036224 Content-Disposition: form-data; name="f[1][edited]" 0 -----------------------------22798303036224 Content-Disposition: form-data; name="d[1]"; filename="БезымÑнный.png" Content-Type: image/png ‰PNG -----------------------------22798303036224 Content-Disposition: form-data; name="f[1][text]" ОпиÑание фото (необÑзательно) -----------------------------22798303036224 Content-Disposition: form-data; name="firstInserted" 1 -----------------------------22798303036224 Content-Disposition: form-data; name="isInBizDir" 0 -----------------------------22798303036224--
Решение задачи: «Загрузить картинку на сайт»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Diagnostics;
using System.IO;
namespace WindowsForms_DownloadFile
{
public partial class Form1 : Form
{
String path;
String fileName;
String fullFileName;
public Form1()
{
InitializeComponent();
path = "E:\\";
fileName = "PhotoCalendar.zip";
fullFileName = Path.Combine(path, fileName);
}
private void btnDownload_Click(object sender, EventArgs e)
{
Uri uri = new Uri("http://dlh.softportal.com/b4/8/3/fa8d5964bf6ca0a5c01524944c3c99c9/PhotoCalendar.zip");
DownloadFile(uri, fullFileName);
}
private void DownloadFile(Uri urlFileInfo, String fileName)
{
WebClient webClient = new WebClient();
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(webClient_DownloadFileCompleted);
webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(webClient_DownloadProgressChanged);
webClient.DownloadFileAsync(urlFileInfo, fileName); //выполняет нормально
}
void webClient_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
double receivedFileSizeToKb = (e.BytesReceived / 1024);
double totalFileSizeToKb = (e.TotalBytesToReceive / 1024);
this.lblDownloadProgress.Text = String.Format("Получено: {0} Kb - Всего: {1} Kb",receivedFileSizeToKb.ToString(), totalFileSizeToKb.ToString());
double percent = (e.TotalBytesToReceive / 100);
int progress = (int)(e.BytesReceived / percent);
this.progressBar.Value = progress;
}
void webClient_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
Process.Start(path);
}
//отправка запроса и получение ответа в RichTextBox
private void button1_Click(object sender, EventArgs e)
{
//Немножко условий,для виду :))
if (String.IsNullOrWhiteSpace(textBox1.Text))
MessageBox.Show("Невозможно отправить GET запрос к адресу", textBox1.Text);
else
{
//Отправляем запрос,где textBox1 - строка с адресом
System.Net.WebRequest reqGET = System.Net.WebRequest.Create(textBox1.Text);
System.Net.WebResponse resp = reqGET.GetResponse();
System.IO.Stream stream = resp.GetResponseStream();
//Получаем ответ в переменную sr и считываем его до конца
System.IO.StreamReader sr = new System.IO.StreamReader(stream, Encoding.Default);
string s = sr.ReadToEnd();
//Выводим всю лабуду в richTextBox1
richTextBox1.Text = s;
}
}
}
}