gpt4 book ai didi

c# - 尝试 GetRequestStream() 时无法连接到远程服务器

转载 作者:太空宇宙 更新时间:2023-11-03 11:24:44 24 4
gpt4 key购买 nike

我有一个很奇怪的问题。

我有一个由 Windows 服务托管的 wcf 调用的方法,当该方法尝试执行 GetRequestStream() 时,我们返回一个异常“无法连接到远程服务器

string strXMLServer = "https://xxxx.webex.com/WBXService/XMLService";

WebRequest request = WebRequest.Create(strXMLServer);
// Set the Method property of the request to POST.
request.Method = "POST";
// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded";

string strXML = XMLmanager.createXML(User, Password, requestType, sessionKey);

byte[] byteArray = Encoding.UTF8.GetBytes(strXML);

// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;

// Get the request stream.
Stream dataStream = request.GetRequestStream(); //<--- here the exception!!
// Write the data to the request stream.
dataStream.Write(byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close();
// Get the response.
WebResponse response = request.GetResponse();

奇怪的是,当我尝试将此应用程序作为独立(控制台应用程序)运行时,我没有遇到任何问题,也没有收到任何错误!只有当我通过 WCF 调用方法时才会出现异常!

最佳答案

听起来您的情况与此类似 SO question .检查运行 Windows 服务的帐户,它很可能没有访问网络资源的权限。

关于c# - 尝试 GetRequestStream() 时无法连接到远程服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9774421/

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