C# で次の curl 呼び出しを行いたい:
curl "http://localhost:8983/solr/update/extract?literal.id=doc1&commit=true" -F "myfile=@tutorial.html"
WebRequest クラスを使用する必要があることがわかりましたが、この部分をどのように処理するかはまだわかりません:
-F "myfile=@tutorial.html"
http://msdn.microsoft.com/en-us/library/debx8sh9.aspxのコードスニペットは、WebRequestクラスを使用してPOSTデータを送信する方法を示しています。
// Create a request using a URL that can receive a post.
WebRequest request = WebRequest.Create("http://localhost:8983/solr/update/extract?literal.id=doc1&commit=true");
// Set the Method property of the request to POST.
request.Method = "POST";
// Create POST data and convert it to a byte array.
string postData = "myfile=@tutorial.html";
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;
WebRequest の代わりに、WebClient クラスの使用を検討してください。これは、WebRequest よりもクリーンでシンプルな構文と見なされるものを提供します。このようなもの:
using (WebClient client = new WebClient())
{
client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
byte[] postResult = client.UploadFile("http://localhost:8983/solr/update/extract?literal.id=doc1&commit=true", "POST", "tutorial.html");
}
http://msdn.microsoft.com/en-us/library/esst63h0%28v=vs.100%29.aspxを参照してください。