No connection could be made because the target machine actively refused it 127.0.0.1

后端 未结 11 2270
野性不改
野性不改 2020-12-15 19:04

I try to connect to a web service hosted on a different server using the WebRequest Class. The web service returns a string as a Response. While doing so I get an Error:

11条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-15 19:38

    Add new WebProxy() for the proxy setting , where you are creating a web request.

    Example :-

      string url =  "Your URL";
      System.Net.WebRequest req = System.Net.WebRequest.Create(url);
      req.Proxy = new WebProxy();
      System.Net.WebResponse resp = req.GetResponse();
    

    Where req.Proxy = new WebProxy() handle the proxy setting & helps the code to work fine.

提交回复
热议问题