c# - C# 中带标志的 cURL 调用

标签 c# .net curl solr

我想在 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/

相关文章:

c# - unity InputField OnValueChanged事件显示InputField.text少一个字符

C# Monotouch/Xamarin.iOS - UILabel 在单个字符串中包含纯文本和斜体文本

php - XAMPP配置cURL错误60:SSL证书

node.js - 在 node.js 中使用带有查询的 Parse.com REST API - 如何使用来自 CURL 的数据编码

c# - 尝试使用 Nancy SuperSimpleViewEngine 渲染局部时获取 [ERR!] 作为输出

java - Microsoft 和 Oracle/Sun 技术之间是否存在等效性?

.NET:有什么方法可以判断对象何时被处理/垃圾收集?

c# - 当 Windows 从 sleep 模式唤醒时启动应用程序

php - 进入 mysql 数据库后,Café 就变成了 Café

c# - 我可以在 VS2010 的 VS2012 中使用静态分析吗?