How to HTTP POST a Blob to a different domain? [du

2019-06-01 19:54发布

问题:

This question already has an answer here:

  • How do I send a cross-domain POST request via JavaScript? 17 answers
  • Ways to circumvent the same-origin policy 11 answers

I have some Blob() object. I want to upload somewhere else (a website that handle user upload through forms).

I can put them in a FormData and send them through an XMLHttpRequest object, but then I can't read the ajax response, because I'm blocked by the same origin policy of the ajax call.

How can I get around this? Is there some way to do a regular upload without using ajax? Is there a way to deal with that "same origin policy" that will work on recent versions of Chrome and Firefox?

edit: Not sure this is a duplicate: I don't control the server being posted, so I'm not OK with just "setting the same origin policy on both domains".

回答1:

In most cases when someone is trying to use AJAX across domains but is blocked by the same origin policy, it is recommended to AJAX to your own PHP page, and then use cURL to send that data to a different site.

http://curl.haxx.se/