我想打在C#中的以下捲曲電話:捲曲電話,旗
curl "http://localhost:8983/solr/update/extract?literal.id=doc1&commit=true" -F "[email protected]"
我發現我應該使用WebRequest類,但我仍然不知道如何處理這部分:
-F "[email protected]"
我想打在C#中的以下捲曲電話:捲曲電話,旗
curl "http://localhost:8983/solr/update/extract?literal.id=doc1&commit=true" -F "[email protected]"
我發現我應該使用WebRequest類,但我仍然不知道如何處理這部分:
-F "[email protected]"
從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 = "[email protected]";
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