简体   繁体   中英

Webexception:remote server returned an error (401)unauthorized

Giving Exception on

HttpWebResponse webresponse = (HttpWebResponse)webrequest.GetResponse();

this line.And Error message is

remote server returned an error 401 unauthorized

It occures only when am calling web service from other project solution... This exception is not occuring when calling service from same project solution.

what should I do to remove this exception and get Response from Remote server?? Plz help me.

Possible solutions can be:

1) add <identity impersonate="true"></identity> in web.config

2) If you have credentials

using (client = new MyWebService())
{
    var username = ConfigurationManager.AppSettings["WSUserName"]
    var password = ConfigurationManager.AppSettings["WSPassword"]
    client.Credentials = new NetworkCredential(username, password);
    // .. and the call here ..
}

Let me know if it doesn't fix your problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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