我正在使用 WebClient 类的 Upload File 方法通过 Http Post 方法将事务发布到服务器。在将事务发布到服务器之前,我会使用当前日期和时间记录此请求,并使用wireshark 记录网络日志。如果我比较两个日志文件的时间,即使两者都在同一台服务器上,同一事务也总是存在 15-30 秒的时间差(网络日志显示时间延迟为 15-30 秒)。
我很惊讶是什么导致了网络延迟,因为在将其登录到日志文件后,我立即将此事务发布到服务器。
我用于发布交易的方法是:-
private BankCommonLayer.httpsResponse SendhttpsMessage(string strRequest, string RRN)
{
BankCommonLayer.httpsResponse hr = new BankCommonLayer.httpsResponse();
string strDirName = ConfigurationSettings.AppSettings["Attachment_file"];
try
{
string strFileName = strDirName + RRN + ".txt";
Microsoft.VisualBasic.FileIO.FileSystem.WriteAllText(strFileName, HexToAscii(strRequest), false, System.Text.Encoding.GetEncoding(28591));
FileInfo fi = new FileInfo(strFileName);
NameValueCollection q = new NameValueCollection();
q.Add("Message", fi.Name);
string url = ConfigurationSettings.AppSettings["https_url"];
WebClient wc = new WebClient();
wc.QueryString = q;
string ResultString = string.Empty;
byte[] postBytes = wc.UploadFile(url, "POST", strFileName);
if (postBytes.Length != 0)
hr.ResponseString = System.Text.Encoding.ASCII.GetString(postBytes).ToString();
else
hr.ResponseString = "No response";
BLCommonFunctions.WriteLogger(1, "FIG Response string :- " + hr.ResponseString.ToString(), ref swLogWriter, strLogPath);
//Write the string to a file.
System.IO.StreamWriter file = new System.IO.StreamWriter(strFileName, true);
file.WriteLine();
file.WriteLine("Response String :" + hr.ResponseString);
file.Close();
Console.WriteLine(hr.ResponseString);
hr.SendSuccess = true;
}
catch (WebException ex)
{
hr.SendSuccess = false;
BLCommonFunctions.WriteLogger(1, "FIG Response string :- NULL (Because " + ex.Message + ")", ref swLogWriter, strLogPath);
}
catch (Exception ex)
{
hr.SendSuccess = false;
BLCommonFunctions.WriteLogger(1, "FIG Response string :- NULL (Because " + ex.Message + ")", ref swLogWriter, strLogPath);
}
return hr;
}