Tag: curl

cURL用C#调用flag

我想在C#中进行以下curl调用: curl “http://localhost:8983/solr/update/extract?literal.id=doc1&commit=true” -F “myfile=@tutorial.html” 我发现我应该使用WebRequest类,但我仍然不确定如何处理这部分: -F “myfile=@tutorial.html”

c# – 使用Cookie的WebRequest HTTP POST(来自curl脚本的端口)

IBM RTC RESTful api提供了一个用于向服务器进行身份validation的shell脚本示例: COOKIES=./cookies.txt USER=my_user PASSWORD=my_password HOST=”https://myJazzServer:9092/jazz” curl -k -c $COOKIES “$HOST/authenticated/identity” curl -k -L -b $COOKIES -c $COOKIES -d j_username=$USER -d j_password=$PASSWORD “$HOST/authenticated/j_security_check” 这非常有效,但我需要使用c#对服务器进行身份validation。 到目前为止,我有以下内容,但它无法正常工作(返回授权失败页面): CookieContainer _cookie; public string _RTC() { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(“https://myJazzServer.com:9092/jazz/authenticated/identity”); if (_cookie == null) { _cookie = new CookieContainer(); } string a; request.CookieContainer = _cookie; using (var response […]

调用ocr.space API时“没有上传文件或提供URL”

我试图从我的C#应用​​程序中调用此API: https : //ocr.space/OCRAPI 当我从curl调用它时,它运行正常: curl -k –form “file=@filename.jpg” –form “apikey=helloworld” –form “language=eng” https://api.ocr.space/Parse/Image 我这样实现了它: [TestMethod] public async Task Test_Curl_Call() { var client = new HttpClient(); String cur_dir = Directory.GetCurrentDirectory(); // Create the HttpContent for the form to be posted. var requestContent = new FormUrlEncodedContent(new[] { new KeyValuePair( “file”, “@filename.jpg”), //I also tried “filename.jpg” new […]

ASP.NET等效于此cURL命令

我正在使用Twilio API,它提供了PHP和Ruby的示例。 我正在一个站点上通过在ASP.NET MVC 3中编码的API发送文本消息,并且使用我对WebRequest对象的有限知识,我能够翻译它: curl -X POST ‘https://api.twilio.com/2010-04-01/Accounts/AC4840da0d7************f98b20b084/SMS/Messages.xml’ \ -d ‘From=%2B14155992671’ \ -u AC4840da0d7************f98b20b084:f7fc2**************75342 进入这个: var request = WebRequest.Create(MessageApiString + “?From=+14*********1&To=” + Phone + “&Body=” + smsCampaign.Message); var user = “AC4840da0d7************f98b20b084”; var pass = “f7fc2**************75342”; string credentials = String.Format(“{0}:{1}”, user, pass); request.Headers.Add(“Authorization”, credentials); var result = request.GetResponse(); 但它没有进行身份validation,我从他们的API获得了401。 cURL -u命令的等效C#是多少? 更新 var request = […]

C#中的curl-F等价物

我试图在C#中使用HTTPClient对象向API发送一个post请求。 这是CURL命令: curl -X POST https://zzz.zzz.zzz/yyy -F Key=abcd -F media=@”audio.aac” 我写了以下代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Net.Http; using System.IO; using System.Net.Http.Headers; namespace Speech2Text { class Program { static void Main(string[] args) { curl().Wait(); } static async Task curl() { var client = new HttpClient(); //Create List of KeyValuePairs List<KeyValuePair> […]

.NET相当于curl将文件上传到REST API?

我需要将一个ics文件上传到REST API。 给出的唯一示例是curl命令。 用于使用curl上传文件的命令如下所示: curl –user {username}:{password} –upload-file /tmp/myappointments.ics http://localhost:7070/home/john.doe/calendar?fmt=ics 如何在C#中使用HttpWebRequest执行此操作? 另请注意,我可能只将ics作为字符串(而不是实际文件)。

Watson对话cURL会话发布请求不传递表单数据

如下所示,在发布cURL请求时尝试继续创建的会话watson而不是返回新的会话。 curl -u “USERNAME”:”PASSWORD” -X POST –form conversation_id=CONVOID –form client_id=CLIENTID –form input=”What type of toppings do you have?” “https://gateway.watsonplatform.net/dialog/api/v1/dialogs/DIALOGID/conversation” 如果我使用下面的cURL它工作正常。 curl -u “USERNAME”:”PASSWORD” –data “conversation_id=CONVOID&client_id=CLIENTID&input=What type of toppings do you have?” https://gateway.watsonplatform.net/dialog/api/v1/dialogs/DIALOGID/conversation 我的问题是,现在当我尝试编写ac#wrapper时,我遇到的问题是POST请求无法正确传输表单数据。 这是怎么回事 ? 我要么需要相当于“ –data ”格式的ac#MVC。 (目前使用HttpClient.PostAsync )或找出使用post请求继续对话的确切错误。 据我所知,我正在正确复制c#中的post请求,所以我不认为有两个问题。 (只有一个发布请求问题,而不是cURL问题,然后是C#实现问题。) 为了我的价值,我以我提交的格式留下命令,只用BLOCKCAPITALS替换敏感值。 如果看起来我错过了引号或大括号,那是因为我有并且可能是问题的原因。

WebRequest等效于CURL命令

我正试图将一个正在运行的curl命令转换为ac#WebRequest。 我已阅读了不少post,我很确定我的代码是正确的,但它仍然无效。 任何人都可以看到我做错了吗? 这是工作curl命令: curl -k -ux:reallylongstring -H “Content-Type: application/json” https://api.somewhere.com/desk/external_api/v1/customers.json 这是我用c#编写的代码: WebRequest wrGETURL; wrGETURL = WebRequest.Create(“https://api.somewhere.com/desk/external_api/v1/customers.json”); wrGETURL.Method = “GET”; wrGETURL.ContentType = “application/json”; wrGETURL.Credentials = new NetworkCredential(“x”, “reallylongstring”); Stream objStream = wrGETURL.GetResponse().GetResponseStream(); StreamReader objReader = new StreamReader(objStream); string responseFromServer = objReader.ReadToEnd(); 但api响应: The remote server returned an error: (406) Not Acceptable. 任何帮助将非常感激! 谢谢

将CURL转换为C#

我花了很多年的时间尝试各种不同的方法将这个curl转换为c#。 请有人帮忙。 我正在尝试做一个httppost并继续得到错误500.这是我要转换的内容: curl –user username:password -X POST -d “browser=Win7x64-C1|Chrome32|1024×768&url=http://www.google.com” http://crossbrowsertesting.com/api/v3/livetests/ 这是我到目前为止: HttpWebRequest request = (HttpWebRequest)WebRequest.Create(baseurl); request.Method = “POST”; request.Accept = “application/json”; request.Credentials = new NetworkCredential(username, password); var response = request.GetResponse(); string text; using (var sr = new StreamReader(response.GetResponseStream())) { text = sr.ReadToEnd(); values.Add(text); } 尝试过这种方法,但它不起作用: List data = new List(); data.Add(“browser=Win7x64-C1|Chrome20|1024×768”); data.Add(“url=URL”); data.Add(“format=json”); data.Add(“callback=doit”); […]

C#中使用C#进行用户身份validation

我想在c#中执行以下cURL请求: curl -u admin:geoserver -v -XPOST -H ‘Content-type: text/xml’ \ -d ‘acme’ \ http://localhost:8080/geoserver/rest/workspaces 我尝试过使用WebRequest: string url = “http://localhost:8080/geoserver/rest/workspaces”; WebRequest request = WebRequest.Create(url); request.ContentType = “Content-type: text/xml”; request.Method = “POST”; request.Credentials = new NetworkCredential(“admin”, “geoserver”); byte[] buffer = Encoding.GetEncoding(“UTF-8”).GetBytes(“my_workspace”); Stream reqstr = request.GetRequestStream(); reqstr.Write(buffer, 0, buffer.Length); reqstr.Close(); WebResponse response = request.GetResponse(); … 但是我收到一个错误:(400)请求不好。 如果我更改请求凭据并在标头中添加身份validation: string […]