[英]webRequest doen't work from different user
我构建了一个小型的Winform应用程序,该应用程序使用一些API发送短信,当我与用户一起在我的工作站上运行它时,一切正常,但是如果我以不同的用户身份在我的工作站上运行它(用于更改该exe文件移位的用户) +鼠标右键):
using (Stream requestStream = restRequest.GetRequestStream())
引发异常
无法建立连接,因为如果(IP地址)目标计算机主动拒绝
但是,当我将应用程序复制到另一个用户站并尝试运行它时,它工作正常,并且对我的用户而言完全相同
问题是代码应该集成到使用具有wcf服务的服务器的应用程序中,该服务将发送短信和iis applicationpool中引发相同异常的用户
会是什么呢 ?
我的简单代码:
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;
}
我解决了问题
在我们公司,我们有代理连接到互联网
当我的用户登录时,他具有GPO(包括代理)所需的所有设置,而当我尝试与其他用户连接时,他根本没有代理设置,这就是问题所在
我所做的只是将代理添加到代码中:
WebProxy proxy = new WebProxy("[my proxy address]", [my proxy port number]);
proxy.BypassProxyOnLocal = false;
request.Proxy = proxy;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.