我已经在我的 Windows 手机中创建了一个“csv 文件”,我想将它发布到服务器中,在网络上,但我不知道我想如何继续,
我不想只用参数发出“发布请求”,我想在服务器中发布我的文件......
实际上,我已连接到此服务器,但它找不到我的文件...
public void SentPostReport()
{
//Post response.
string url = this.CurentReportkPI.configXml.gw; // string url
Uri uri = new Uri(url);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.Accept = "application/CSV";
request.Method = "POST";
request.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), request);
}
private void GetRequestStreamCallback(IAsyncResult asynchronousResult)
{
HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
// End the operation
Stream postStream = request.EndGetRequestStream(asynchronousResult);
// I create My csv File
CreateCsv reportCsv = new CreateCsv();
string pathReportFile = reportCsv.CreateNewReport(this.report);
string CsvContent = reportCsv.ReadFile(pathReportFile);
// Convert the string into a byte array.
byte[] byteArray = Encoding.UTF8.GetBytes(CsvContent);
// Write to the request stream.
postStream.Write(byteArray, 0, byteArray.Length);
postStream.Close();
// Start the asynchronous operation to get the response
request.BeginGetResponse(new AsyncCallback(GetResponseCallback), request);
}
private static void GetResponseCallback(IAsyncResult asynchronousResult)
{
Debug.WriteLine("GetResponseCallback");
HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
// End the operation
HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult);
Stream streamResponse = response.GetResponseStream();
StreamReader streamRead = new StreamReader(streamResponse);
string responseString = streamRead.ReadLine();
// Close the stream object
streamResponse.Close();
streamRead.Close();
// Release the HttpWebResponse
response.Close();
}
当我着手解决我的问题并将我的 CSV 文件与我的请求一起发送时,你有什么想法吗?
谢谢。