Sunday

csharp post form data

     
public string POST(string url, string username,string password, string postParams)
{


//Our getVars, to test the get of our php.
//We can get a page without any of these vars too though.
//string getVars = "?var1=test1&var2=test2";
//Initialization, we use localhost, change if applicable
HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(url);
WebReq.UserAgent = GetRndUserAgent();

string Credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(username + ":" + password));

WebReq.Method = "POST";
WebReq.ContentType = "application/xml";
WebReq.AllowWriteStreamBuffering = true;

WebReq.Headers.Add("Authorization", "Basic " + Credentials);

WebReq.ServicePoint.Expect100Continue = false;



// string postParams = "name=some sort of value";
if (postParams != string.Empty)
{
byte[] buffer = ASCIIEncoding.UTF8.GetBytes(postParams);
WebReq.ContentLength = buffer.Length;
using (Stream writer = WebReq.GetRequestStream())
{

writer.Write(buffer, 0, buffer.Length);

}
}

//From here on, it's all the same as above.
HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
//Let's show some information about the response
//_log(WebResp.StatusCode.ToString());
//_log(WebResp.Server);

//Now, we read the response (the string), and output it.
Stream Answer = WebResp.GetResponseStream();
StreamReader _Answer = new StreamReader(Answer);
return _Answer.ReadToEnd();


}

No comments:

imagemagic add text to image

rem different types of text annotations on existing images rem cyan yellow orange gold rem -gravity SouthWest rem draw text and anno...