简体   繁体   English

webRequest无法从其他用户使用

[英]webRequest doen't work from different user

I build a small winform application that use some API for sending sms messages, when i run it on my station with my user everything works great but if i run it on my station but as different user (for changing the user on that exe file shift + right mouse button): 我构建了一个小型的Winform应用程序,该应用程序使用一些API发送短信,当我与用户一起在我的工作站上运行它时,一切正常,但是如果我以不同的用户身份在我的工作站上运行它(用于更改该exe文件移位的用户) +鼠标右键):

using (Stream requestStream = restRequest.GetRequestStream())

throws exception 引发异常

No connectuion could be made because the target machine actively refused if (ip address) 无法建立连接,因为如果(IP地址)目标计算机主动拒绝

but when i copy the app to the other user station and try to run it it's work fine and doing exactly the same for my user 但是,当我将应用程序复制到另一个用户站并尝试运行它时,它工作正常,并且对我的用户而言完全相同

the problem is that the code should be integrated to application that use server that have wcf service that will send the sms's and the user that in iis applicationpool throwing that same exception 问题是代码应该集成到使用具有wcf服务的服务器的应用程序中,该服务将发送短信和iis applicationpool中引发相同异常的用户

what could it be ? 会是什么呢 ?

my simple code: 我的简单代码:

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;
}

I get the problem solved 我解决了问题

in our company we have proxy for connecting to the internet 在我们公司,我们有代理连接到互联网

when my user was logged on he has all the settings he needed from the GPO (include proxy) when i tried to connect with other user he simply didn't have the proxy settings and that was the issue 当我的用户登录时,他具有GPO(包括代理)所需的所有设置,而当我尝试与其他用户连接时,他根本没有代理设置,这就是问题所在

what i did is simply added proxy to the code: 我所做的只是将代理添加到代码中:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM