Canonical HTTP POST code?

前端 未结 3 1449
攒了一身酷
攒了一身酷 2021-02-05 13:10

I\'ve seen so many implementations of sending an http post, and admittedly I don\'t fully understand the underlying details to know what\'s required.

What is the

3条回答
  •  长情又很酷
    2021-02-05 13:33

    As others have said, WebClient.UploadString (or UploadData) is the way to go.

    However the built-in WebClient has a major drawback : you have almost no control over the WebRequest that is used behind the scene (cookies, authentication, custom headers...). A simple way to solve that issue is to create your custom WebClient and override the GetWebRequest method. You can then customize the request before it is sent (you can do the same for the response by overridingGetWebResponse). Here is an example of a cookie-aware WebClient. It's so simple it makes me wonder why the built-in WebClient doesn't handle it out-of-the-box...

提交回复
热议问题