Reuse Connection with HttpWebRequest in C#

后端 未结 2 359
感动是毒
感动是毒 2021-01-15 00:47

I need to make a POST request using .Net.

I can authenticate by GET, and so I’m trying to make a POST request on the same connection to keep my authentication.

相关标签:
2条回答
  • 2021-01-15 01:45

    The reason you don't stay logged in is because you don't give the HttpWebRequest a CookieContainer to keep the session id in.

    See the following to StackOverflow Q&A's for your possible solution:

    C# keep session id over httpwebrequest

    Multiple WebRequest in same session

    I hope this helped.

    0 讨论(0)
  • 2021-01-15 01:45

    Any idea how the authentication is managed on the other end? IE. If it sets a cookie, then you need to make sure you account for that, see this page, and specifically this note:

    Note

    For security reasons, cookies are disabled by default. If you want to use cookies, use the CookieContainer property to enable cookies.

    0 讨论(0)
提交回复
热议问题