我想在 C# 中进行以下curl 调用:
curl "http://localhost:8983/solr/update/extract?literal.id=doc1&commit=true" -F "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bfd2c6d9d6d3da82ffcbcacbd0cdd6ded391d7cbd2d3" rel="noreferrer noopener nofollow">[email protected]</a>"
我发现我应该使用 WebRequest 类,但我仍然不确定如何处理这部分:
-F "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="83eefae5eaefe6bec3f7f6f7ecf1eae2efadebf7eeef" rel="noreferrer noopener nofollow">[email protected]</a>"
最佳答案
来自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 = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b8d5c1ded1d4dd85f8cccdccd7cad1d9d496d0ccd5d4" rel="noreferrer noopener nofollow">[email protected]</a>";
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;
关于c# - C# 中带标志的 cURL 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12398541/