C
Captain Kernel
Guest
Hi,
I'm in a hurry and doing ten things at once here so I need a favor, how would this code look if written using RestSharp?
private void Button1_Click(object sender, System.EventArgs e)
{
ASCIIEncoding encoding = new ASCIIEncoding(); string postData =
"CUSTOMER_NBR=" + HttpUtility.UrlEncode("7000") +
"&MERCHANT_NBR=" + HttpUtility.UrlEncode("700010") +
"&DBAVAL_NBR=" + HttpUtility.UrlEncode("1") +
"&TERMINAL_NBR=" + HttpUtility.UrlEncode("1") +
"&TRAN_TYPE =" +HttpUtility.UrlEncode("CCM1") +
"&PRICE=" + HttpUtility.UrlEncode("12.95") +
"&TRANSFER_VAL=" + HttpUtility.UrlEncode("1") +
"&BATCH_MODE=" + HttpUtility.UrlEncode("5") +
"&USER_ENT_METH=" + HttpUtility.UrlEncode("X") +
"&ACCOUNT_DATA=" + HttpUtility.UrlEncode("4110231398111234") + "&EXPENSE_DATE="
+ HttpUtility.UrlEncode("0605");
byte[] data = encoding.GetBytes(postData);
// Prepare web request...
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("Oops, an error occurred!");
myRequest.Method = "POST"; myRequest.ContentType = "application/x-www-formurlencoded"; myRequest.ContentLength = data.Length;
Stream newStream = myRequest.GetRequestStream();
// Send the data. newStream.Write(data,0,data.Length); newStream.Close();
HttpWebResponse loWebResponse = (HttpWebResponse)myRequest.GetResponse();
Encoding enc = System.Text.Encoding.GetEncoding(1252); StreamReader
loResponseStream =
new StreamReader(loWebResponse.GetResponseStream(), enc);
string lcHtml = loResponseStream.ReadToEnd(); loWebResponse.Close();
loResponseStream.Close();
TextBox1.Text = lcHtml;
}
}
I'm not entirely clear on the exact way RestSharp does this (for example do I use AddParameter with ParameterType.RequestBody ?).
Any help much appreciated.
ThANKS
PS: I need to use RestSharp as its our preferred library for this and we're doing this async, I just need to know the equivalent steps one would use - I can study this and get there myself but the time is a pain!
Continue reading...
I'm in a hurry and doing ten things at once here so I need a favor, how would this code look if written using RestSharp?
private void Button1_Click(object sender, System.EventArgs e)
{
ASCIIEncoding encoding = new ASCIIEncoding(); string postData =
"CUSTOMER_NBR=" + HttpUtility.UrlEncode("7000") +
"&MERCHANT_NBR=" + HttpUtility.UrlEncode("700010") +
"&DBAVAL_NBR=" + HttpUtility.UrlEncode("1") +
"&TERMINAL_NBR=" + HttpUtility.UrlEncode("1") +
"&TRAN_TYPE =" +HttpUtility.UrlEncode("CCM1") +
"&PRICE=" + HttpUtility.UrlEncode("12.95") +
"&TRANSFER_VAL=" + HttpUtility.UrlEncode("1") +
"&BATCH_MODE=" + HttpUtility.UrlEncode("5") +
"&USER_ENT_METH=" + HttpUtility.UrlEncode("X") +
"&ACCOUNT_DATA=" + HttpUtility.UrlEncode("4110231398111234") + "&EXPENSE_DATE="
+ HttpUtility.UrlEncode("0605");
byte[] data = encoding.GetBytes(postData);
// Prepare web request...
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("Oops, an error occurred!");
myRequest.Method = "POST"; myRequest.ContentType = "application/x-www-formurlencoded"; myRequest.ContentLength = data.Length;
Stream newStream = myRequest.GetRequestStream();
// Send the data. newStream.Write(data,0,data.Length); newStream.Close();
HttpWebResponse loWebResponse = (HttpWebResponse)myRequest.GetResponse();
Encoding enc = System.Text.Encoding.GetEncoding(1252); StreamReader
loResponseStream =
new StreamReader(loWebResponse.GetResponseStream(), enc);
string lcHtml = loResponseStream.ReadToEnd(); loWebResponse.Close();
loResponseStream.Close();
TextBox1.Text = lcHtml;
}
}
I'm not entirely clear on the exact way RestSharp does this (for example do I use AddParameter with ParameterType.RequestBody ?).
Any help much appreciated.
ThANKS
PS: I need to use RestSharp as its our preferred library for this and we're doing this async, I just need to know the equivalent steps one would use - I can study this and get there myself but the time is a pain!
Continue reading...