将Curl脚本转换为C#

时间:2015-09-10 11:57:01

标签: c# curl

我有一个下载文件的curl脚本。如何将其转换为C#?

Dim strCurl1 
Dim strCurl2 
Dim strCurl3 
Dim strCurl4 

strCurl1 = "c:\temp\Curl\curl -d "
strCurl2 = "username=myUser&password=passwrd&asof=" & fileName & "&format=csv"
strCurl3 = "https://website/PresentValueServlet > " & "c:\temp\Curl\Results_" & fileName & ".csv"
strCurl4 = strCurl1 & Chr(34) & strCurl2 & Chr(34) & " " & strCurl3 & " --insecure  --proxy proxy.myserver.com:8080 --proxy-user admin:passAdmin"

Set objShell = CreateObject("WScript.Shell")
objShell.run "cmd /K " & strCurl4

我的C#到目前为止......

string username = "myUser";
string password = "passwrd";
string fileDestination = @"c:\temp\Curl\Results_" + fileName + ".csv";
using (WebClient client = new WebClient())
{
   client.Credentials = new NetworkCredential(username, password);
   client.DownloadFile(string.Format("https://website/PresentValueServlet"), fileDestination);
}

使用代理更新了C#代码...

WebProxy proxy = new WebProxy("myurl:8080", true);
proxy.Credentials = new NetworkCredential("admin", "pswrd");
client.Proxy = proxy;

错误远程服务器返回错误:(403)禁止。

0 个答案:

没有答案