卷曲的呼叫在C#中,旗 [英] cURL call in C# with flag

查看:201
本文介绍了卷曲的呼叫在C#中,旗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提出在C#中的以下卷曲电话:

 卷曲的http://本地主机:8983 / Solr的/更新/提取literal.id = DOC1和放大器;提交=真正的Fmyfile=@tutorial.html
 

我发现我应该使用WebRequest类,但我仍然不知道如何处理这部分:

  -Fmyfile=@tutorial.html
 

解决方案

从的 http://msdn.microsoft.com/en-us/library/debx8sh9.aspx 展示了如何使用WebRequest类来发送POST数据:

  //创建使用,它可以接收后的URL的请求。
WebRequest的请求= WebRequest.Create(HTTP://本地主机:8983 / Solr的/更新/提取literal.id = DOC1和放大器;提交=真正的);
//请求POST的方法属性设置。
request.Method =POST;
//创建POST数据并将其转换为一个字节数组。
字符串POSTDATA =myfile=@tutorial.html;
字节[]的字节数组= Encoding.UTF8.GetBytes(POSTDATA);
//了的WebRequest的ContentType属性设置。
request.ContentType =应用/的X WWW的形式urlen codeD;
//设置的WebRequest的CONTENTLENGTH财产。
request.ContentLength = byteArray.Length;
 

I'd like to make a following curl call in C#:

curl "http://localhost:8983/solr/update/extract?literal.id=doc1&commit=true" -F "myfile=@tutorial.html"

I found that I should use WebRequest class, but I'm still not sure how deal with this part:

-F "myfile=@tutorial.html"

解决方案

The code snippet from http://msdn.microsoft.com/en-us/library/debx8sh9.aspx shows how to send POST data using the WebRequest class:

// 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;

这篇关于卷曲的呼叫在C#中,旗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆