2011-07-20 15 views
2

私はWebアプリケーションにシートデータを送信するためのMicrosoft Excelプラグインを開発しようとしています。プラグインはユーザー名とパスワードの入力を要求し、WebアプリケーションにログインHTTPリクエストを送信してセッションを取得する必要があります。その後、Webアプリケーションにデータをアップロードします。私は何を使うべきですか?httpリクエストを送信するためのC#方法を見つける

+1

はただ、これを使用してみてください:http://msdn.microsoft.com/en-us/library/system.web .httprequest.aspx詳細な回答が必要な場合は、コードを提供する必要があります。あなたがしたいことを正確にやっている例は何百もあります。あなたがしなければならないことは、主題についての研究をすることだけです。 –

答えて

5

投稿方法ユーザ名とパスワードを送信するためのサンプル。ファイルをアップロードするためだけgoogle.comやbing.comで「ファイルアップロードのC#」を検索したり、C#'s WebClient.UploadFile, Code Project

// Create a request using a URL that can receive a post. 
WebRequest request = WebRequest.Create("http://example.com"); 
// Set the Method property of the request to POST. 
request.Method = "POST"; 
// Create POST data and convert it to a byte array. 
string postData = "username=user&passsword=pass"; 
byte[] byteArray = Encoding.UTF8.GetBytes (postData); 
// Set the ContentType property of the WebRequest. 
request.ContentType = "application/x-www-form-urlencoded"; 
// Set the ContentLength property of the WebRequest. 
request.ContentLength = byteArray.Length; 
// Get the request stream. 
Stream dataStream = request.GetRequestStream(); 
// Write the data to the request stream. 
dataStream.Write (byteArray, 0, byteArray.Length); 
// Close the Stream object. 
dataStream.Close(); 
// Get the response. 
WebResponse response = request.GetResponse(); 
// Display the status. 
Console.WriteLine (((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. 
Console.WriteLine (responseFromServer); 
// Clean up the streams. 
reader.Close(); 
dataStream.Close(); 
response.Close();                       
関連する問題