gpt4 book ai didi

.net - 使用 webrequest 时如何保持连接?

转载 作者:行者123 更新时间:2023-11-30 18:06:56 26 4
gpt4 key购买 nike

string strURL = (Request.IsSecureConnection ? "https://website.com/Transaction.asmx": "http://website.com/wTransaction.asmx");

string strCommand = clsMisc.strGetDataFromPage(this, "c", "", PostMethod.BOTH);string strAppCode = clsMisc.strGetDataFromPage(this, "a", "WEBIN", PostMethod.BOTH);string strVenueCode = clsMisc.strGetDataFromPage(this, "v", "", PostMethod.BOTH);long transcationid= long.Parse(clsMisc.strGetDataFromPage(this, "t", "0", PostMethod.BOTH)); 字符串 strParam1 = clsMisc.strGetDataFromPage(this, "p1", "", PostMethod.BOTH); string strParam2 = clsMisc.strGetDataFromPage(this, "p2", "", PostMethod.BOTH); 字符串 strParam3 = clsMisc.strGetDataFromPage(this, "p3", "", PostMethod.BOTH); 字符串 strParam4 = clsMisc.strGetDataFromPage(this, "p4", "", PostMethod.BOTH);

            StringBuilder sbrPost = new StringBuilder();

string strIPAddress = Request.UserHostAddress.ToString();
if (Request.Headers.ToString().Contains("&X-Forwarded-For="))
{
strIPAddress = Request.Headers["X-Forwarded-For"].ToString();
}
strAppCode = "|APPCODE=" + strAppCode + "|IPADDRESS=" + strIPAddress + "|";

//strAppCode = "|APPCODE=" + strAppCode + "|IPADDRESS=" + Request.UserHostAddress.ToString() + "|";

sbrPost.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
sbrPost.Append("<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\"><soap12:Body><objExecute xmlns=\"http://www.website.com/\">");
sbrPost.Append("<strAppCode>" + strAppCode + "</strAppCode>");
sbrPost.Append("<lngTransactionIdentifier>" + lngTransId + "</lngTransactionIdentifier>");
sbrPost.Append("<strCommand>" + strCommand + "</strCommand>");
sbrPost.Append("<strParam1>" + strParam1 + "</strParam1>");
sbrPost.Append("<strParam2>" + strParam2 + "</strParam2>");
sbrPost.Append("<strParam3>" + strParam3 + "</strParam3>");
sbrPost.Append("<strParam4>" + strParam4 + "</strParam4>");
</objExecute></soap12:Body></soap12:Envelope>");
string strPost = sbrPost.ToString();

WebRequest objReq = WebRequest.Create(strURL);
WebResponse objRes;
StreamReader smrRes;

byte[] bytData = Encoding.UTF8.GetBytes(strPost);
objReq.Method = "POST";
objReq.ContentType = "application/soap+xml";
objReq.ContentLength = bytData.Length;
objReq.Timeout = 600000; // 10 minutes
Stream objPost = objReq.GetRequestStream();
objPost.Write(bytData, 0, bytData.Length);
objPost.Close();
objRes = objReq.GetResponse();
smrRes = new StreamReader(objRes.GetResponseStream());
Response.Write(smrRes.ReadToEnd());
Response.ContentType = "text/xml";
smrRes.Close();
Response.End();
}
catch (Exception err)
{
clsLog.blnLogError(strErrorPage,strErrorMethod, "",err.Message);
}
}

我在 da line objPost.Close();.....不寻常的错误是,当我在 Visual Studio 2010 中使用 F10 缓慢地逐行调试此代码时......代码可以工作......但是当我只是运行程序或什至快速调试程序时...它会在那一行抛出一个错误..它给出一个错误,表明预期打开的连接已被服务器关闭..

天哪!!!

最佳答案

如果您在调试时认为 Thread.Sleep(10000) 工作正常,请尝试一下。

关于.net - 使用 webrequest 时如何保持连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5230221/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com