HTTPS C# Post?

2019-05-20 08:08发布

I am trying to login to a HTTPS website and then navigate to download a report using c# (its an xml report) ?

I have managed to login OK via cookies/headers etc - but whenever I navigate to the link once logged in, my connection takes me to the "logged out" page ?

Anyone know what would cause this ?

2条回答
做个烂人
2楼-- · 2019-05-20 08:24

Make sure the CookieContainer you use for your login is the same one you use when downloading the actual report.

var cookies = new CookieContainer();
var wr1 = (HttpWebRequest) HttpWebRequest.Create(url1);
wr1.CookieContainer = cookies;
// do login here with wr1

var wr2 = (HttpWebRequest) HttpWebRequest.Create(url2);
wr2.CookieContainer = cookies;
// get the report with wr2
查看更多
Emotional °昔
3楼-- · 2019-05-20 08:36

It can be any number of reasons. Did you pass in the cookie to the download request? Did you pass a referrer URL?

The best way to check is to record a working HTTP request with Wireshark or any number of Firefox extensions or Fiddler.

Then try to recreate the request in C#

查看更多
登录 后发表回答