Asp.net Cross Domain Form Posting

2020-03-26 05:39发布

问题:

Is it possible to post data from an asp.net application in one domain to another application on a different domain?

I've seen some of the posts where people mention some rather strange ways to inject forms into the response stream, but this seems overkill.

Is it possible and what is the best way to achieve it without hacking Asp.net to death?

Thanks, Jacques

回答1:

It's absolutely possible, and pretty easy to do.

  1. Browser posts data to your .net app
  2. Your app uses the HttpWebRequest object to post data to the 3rd party site
  3. 3rd party site gives data back to your app or simply accepts post.
  4. Your app responds to the browser with whatever you need.

I have no idea why you would "inject forms into the response stream" or do anything funky like that. Perhaps you could add a bit more about your requirements.

Chris.



回答2:

If you have access to both applications then the best way is to do it server side.

So make a web service available and consume it from the posting application.

or

Use httpwebrequest server side, see link below.

http://www.netomatix.com/httppostdata.aspx

On the client you could use a library such as http://easyxdm.net/wp/ - though there is a bit of a learning curve.

Here are a couple of links that may help you if you dont want to use the above routes and are prepared to edit your asp.net pages.

http://blog.dmbcllc.com/2009/11/11/asp-net-cross-domain-form-submission/

Cross-Domain Posting in ASP.Net loses Form Fields



标签: asp.net