如何从CURL.exe中检索数据?

时间:2012-03-15 11:02:55

标签: c# curl

我在C#中调用CURL来检索数据。

以下是我的代码:

Process p = new Process();
p.StartInfo.WorkingDirectory = @"D:\";
p.StartInfo.FileName = @"D:\curl.exe";
p.StartInfo.CreateNoWindow = true;
p.StartInfo.Arguments = "-u agentemail:password -k https://fantasia.zendesk.com/api/v1/tickets/1.xml";
p.Start();
p.WaitForExit();

但问题是在CURL获取URL数据后,如何从CURL中检索数据? 是否有命令将数据拉入如下字符串?

string x = p.OutputDataReceived();

p.OutputDataReceived(string x);

非常感谢。

2 个答案:

答案 0 :(得分:2)

ProcessStartInfo start = new ProcessStartInfo();

start.FileName = @"C:\curl.exe";  // Specify exe name.

start.Arguments = "-i -X POST -H \"Content-Type: text/xml\" -u \"curl:D6i\" --insecure --data-binary @" + cestaXmlUsers + " \"https://xxx.sk/users-import\"";

start.UseShellExecute = false;

start.RedirectStandardOutput = true;

Process p = Process.Start(start);

string result = p.StandardOutput.ReadToEnd();

p.WaitForExit();

答案 1 :(得分:1)

您可以添加以下行:

ProcessStartInfo start = new ProcessStartInfo();
start.FileName = @"D:\curl.exe";  // Specify exe name.
start.Arguments = "-u agentemail:password -k https://fantasia.zendesk.com/api/v1/tickets/1.xml";
start.UseShellExecute = false;
start.RedirectStandardOutput = true;

// Start the process.
using (Process p = Process.Start(start)) {
    // Read in all the text from the process with the StreamReader
    using (StreamReader reader = p.StandardOutput) {
        string result = reader.ReadToEnd();
        Console.Write(result);
    }
}
相关问题