參數處理部分
//Format the data
string output = data.Aggregate(String.Empty, (current, keyValuePair) => current + ("&" + keyValuePair.Key + "=" + HttpUtility.UrlEncode(keyValuePair.Value)));
var encoding = new UTF8Encoding();
//設定PostData變數將output進行處理,最終得到byte[] d作為最終資料寫入到WebRequest中
var Postdata = Encoding.ASCII.GetBytes(output);
byte[] d = encoding.GetBytes(output.Substring(1, output.Length - 1));
var address = TargetUrl;
//GET部分的資料處理
if (method.ToUpperInvariant() == "GET")
address=address+output;
//POST部分的資料處理
WebRequest request = WebRequest.Create(address) as HttpWebRequest;
//Add post process
if (request == null)
throw new Exception("WebRequest object is null.");