2

WinFormsアプリケーションを開発していて、バイナリイメージデータをWebアプリケーションに送信したいと考えています。それはどのように機能しますか?

私はこれをコーディングしました:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";

request.AllowWriteStreamBuffering = true;
request.KeepAlive = true;                
request.Credentials = System.Net.CredentialCache.DefaultCredentials;

var fc = GetFileContent(varsayilanResimGuid);
byte[] postBytes = fc.Dosya;
request.ContentLength = postBytes.LongLength;
Stream requestStream = request.GetRequestStream();               
requestStream.Write(postBytes, 0, postBytes.Length);
requestStream.Close();                

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string content = new StreamReader(response.GetResponseStream()).ReadToEnd(); 

.ashxでこのバイナリイメージコンテンツを受け取る方法は?

4

1 に答える 1

0

質問して答えます。
バイナリイメージを受信する方法:

Stream gelenResim = context.Request.InputStream;

if (gelenResim.Length == 0) 
{
    e.Resim = "/Content/EmlakDetayImaj/Noimages.jpg";
}

string guidim = Guid.NewGuid().ToString().Substring(0, 4);
var KaydetResimDosya = "/Content/EmlakDetayImaj/" + guidim + ".jpg";

using (FileStream fileStream = System.IO.File.Create(context.Server.MapPath("~/Content/EmlakDetayImaj/" + guidim + ".jpg"), (int)gelenResim.Length))
{
    byte[] bytesInStream = new byte[gelenResim.Length];
    gelenResim.Read(bytesInStream, 0, (int)bytesInStream.Length);
    fileStream.Write(bytesInStream, 0, bytesInStream.Length);
}
于 2012-05-02T11:30:47.987 に答える