我有一個C#.net Web應用程序。我試圖從後一個應用程序二進制數據到另一個使用此代碼如何檢索發佈的數據(以字節[]格式)?
string url = "path to send the data";
string result=null;
string postData = "This is a test that posts this string to a Web server.";
byte[] fileData = Encoding.UTF8.GetBytes (postData);
// Create a request using a URL that can receive a post.
WebRequest request = WebRequest.Create (url);
// Set the Method property of the request to POST.
request.Method = "POST";
// Create POST data and convert it to a byte array.
// Set the ContentType property of the WebRequest.
request.ContentType = "multipart/form-data";
// Set the ContentLength property of the WebRequest.
request.ContentLength = fileData.Length;
// Get the request stream.
Stream dataStream = request.GetRequestStream();
// Write the data to the request stream.
dataStream.Write (fileData, 0, fileData.Length);
// Close the Stream object.
dataStream.Close();
// Get the response.
WebResponse response = request.GetResponse();
// Display the status.
result = ((HttpWebResponse)response).StatusDescription;
// Get the stream containing content returned by the server.
dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader (dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
// Display the content.
result = result + responseFromServer;
// Clean up the streams.
reader.Close();
dataStream.Close();
response.Close();
通過上面的代碼,我送byte[]
到第二個應用程序。如何在第二個應用程序中檢索發佈的數據(格式爲byte[]
)?
什麼樣的應用呢? – 2013-04-04 10:29:02
其網絡應用程序 – Sudha 2013-04-04 10:37:51