简体   繁体   中英

How to implement Javascript's XmlHttpRequest in C#?

There is an old article in the MSDN Magazine with a walk-through to implement in C# the equivalent of the Javascript XMLHttpRequest object.

I find it very interesting but the code is not downloadable anymore.

Do you know of an implementation similar to the Javascript XMLHttpRequest object but in C#? Among other thinks, this implementation can:

  • Send http requests to the server.
  • Send requests both synchronously and asynchronously.
  • Allows to abort long running processes.

I know it all can be done easily with the HTTPWebRequest object in .NET, but after reading the article I was hoping that a wrapper would be available as it used to be in the code of that article (the link is dead).

Thanks,

看一下WebClient类

You can use WebClient.DownloadString that is a good wrapper around a web request. You can have a non blocking call too ( the better way ) by using DownloadStringAsync

You can use WebClient, though I often find it wraps a bit too much and I end up going back to HTTPWebRequest.

There's plenty of the code from that article in it's figures at http://msdn.microsoft.com/hr-hr/magazine/bb985675%28en-us%29.aspx Enough really to reconstruct the whole thing.

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