Convert CURL to C#

后端 未结 2 852
面向向阳花
面向向阳花 2020-12-03 15:32

I have spent ages trying various different ways to convert this curl to c#. Could someone please help. I am trying to do a http post and keep getting error 500. here is what

相关标签:
2条回答
  • 2020-12-03 15:52

    Just implemented an experimental ASP.NET Core app that turns curl commands into C# code using Roslyn

    Give it a try, please:
    https://curl.olsh.me/

    0 讨论(0)
  • I modified the first one to write data to the request stream as per http://msdn.microsoft.com/en-us/library/debx8sh9(v=vs.110).aspx, does this work:

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(baseurl);
    request.Method = "POST";
    request.Accept = "application/json";
    request.Credentials = new NetworkCredential(username, password);
    request.UserAgent = "curl/7.37.0";
    request.ContentType = "application/x-www-form-urlencoded";
    
    using (var streamWriter = new StreamWriter(request.GetRequestStream()))
    {
        string data = "browser=Win7x64-C1|Chrome32|1024x768&url=http://www.google.com";
    
        streamWriter.Write(data);
    }
    
    var response = request.GetResponse();
    string text;
    
    using (var sr = new StreamReader(response.GetResponseStream()))
    {
        text = sr.ReadToEnd();
        values.Add(text);
    }
    
    0 讨论(0)
提交回复
热议问题