当我用我的用户在我的工作站上运行它时,一切都很好,但如果我在我的工作站上以不同的用户身份运行它(用于在exe文件上更改用户shift+鼠标右键):
using (Stream requestStream = restRequest.GetRequestStream())
引发异常
无法建立连接,因为目标计算机处于活动状态
但是,当我将应用程序复制到另一个用户站并尝试运行它时,它工作正常,对我的用户来说也完全一样
可能是什么?
我的简单代码:
JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
Dictionary<string, object> deserializedJsonDictionary;
HttpWebRequest restRequest;
WebResponse restResponse;
try
{
string connectionParams = "{some json params for api...}";
restRequest = (HttpWebRequest)WebRequest.Create(URI);
restRequest.Method = Method; //post
restRequest.ContentType = ContentType; // application/json
using (Stream requestStream = restRequest.GetRequestStream())
{
byte[] inputStringBytes = Encoding.UTF8.GetBytes(connectionParams);
requestStream.Write(inputStringBytes, 0, inputStringBytes.Length);
}
using (restResponse = restRequest.GetResponse())
{
using (Stream responseStream = restResponse.GetResponseStream())
{
StreamReader rdr = new StreamReader(responseStream, Encoding.UTF8);
string Json = rdr.ReadToEnd();
deserializedJsonDictionary = (Dictionary<string, object>)jsonSerializer.DeserializeObject(Json);
}
}
}
catch(Exception ex)
{
throw ex;
}