0

I am using restsharp to get content from a web service. When I execute the restsharp request it redirects me to a login page. What is the best way to handle this.

Here is the code im using

var client = new RestClient("url");
var request = new RestRequest(Method.POST);
var response = client.Execute(request);
var content = response.Content; // raw content as string            
System.Console.Write(content);
var t = System.Console.ReadLine();
Luke101
  • 59,479
  • 80
  • 216
  • 348

1 Answers1

1

Sounds like the WebService is hosted within a WebSite using Forms Authentication. Can you change the authentication type, or implement a login service method? That would probably be the simplest, most correct way of doing this.

The other option is to visit the page in a web browser, and get redirected to the login page. You can then examine the page and contents of the POSTed form when supplying credentials in order to mimic a login from within your code.

Erix
  • 6,857
  • 2
  • 33
  • 60