Click here to Skip to main content
15,893,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am banging my head against a wall trying to convert a working curl command to a c# WebRequest.

I have read through quite a few postings but didn't get satisfactory answer

Here is the working curl command:

curl -K pathtoconfigfile http://myserver/someservlet which processing the post command

Any help would be much appreciated!
Posted
Comments
Zoltán Zörgő 22-Feb-15 14:11pm    
Why? If you like curl, use curl! Jump here: and see my answer.
Kuthuparakkal 22-Feb-15 16:39pm    
Try this:

public static HttpWebResponse POST(string postData, string url, string referer, CookieContainer cookie)
{
try
{
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
request.Method = "POST";
request.KeepAlive = true;
request.AllowAutoRedirect = false;
request.Accept = "*/*";
request.ContentType = "application/x-www-form-urlencoded";
request.CookieContainer = cookie;
if (!string.IsNullOrEmpty(referer))
request.Referer = referer;
request.ContentLength = byteArray.Length;
request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5";
// request.Proxy = null;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
return (HttpWebResponse)request.GetResponse();
}
catch
{
return (HttpWebResponse)null;
}
}
Member 11377605 23-Feb-15 2:46am    
Hi Kuthuparakkal what is the use of string referer here
Kuthuparakkal 23-Feb-15 6:46am    
Some webapp checks whats the link before post to ensure max security

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900