0

I'm trying to upload a file (which can be quite large) from the website of one server to the backend of another server using plupload. Lets say:

domain 1 = http://www.websitedomain.com/uploadform
domain 2 = http://www.backenddomain.com/uploadhandler

Trying to upload i send the following:

OPTIONS /main/uploadnetwork.php HTTP/1.1
Host: backenddomain.com
Connection: keep-alive
Access-Control-Request-Method: POST
Origin: http://www.websitedomain.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.79 Safari/537.4
Access-Control-Request-Headers: origin, content-type
Accept: */*
Referer: http://www.websitedomain.com/uploadform
Accept-Encoding: gzip,deflate,sdch
Accept-Language: nl-NL,nl;q=0.8,en-US;q=0.6,en;q=0.4
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
DNT: 1

But when I try to start the upload the server returns the following:

HTTP/1.1 405 Method Not Allowed
Allow: GET, HEAD, OPTIONS, TRACE
Content-Type: text/html
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
X-Powered-By-Plesk: PleskWin
Date: Mon, 01 Oct 2012 12:41:57 GMT
Content-Length: 999

After doing some research I found out that a browser does this to check if the server will accept the intended message. It looks like my server doesn't feel like accepting a simple POST call even tho i use post all the time.

The Google Chrome console gives the following error:

XMLHttpRequest cannot load http://www.backenddomain.com/uploadhandler. Origin http://www.websitedomain.com is not allowed by Access-Control-Allow-Origin.

Does anyone know how to stop the browser from checking or how i can tell my server to just accept the POST?

dragon112
  • 137
  • 3
  • 9

3 Answers3

0

The browser is probably not allowing cross site connections. Check this site for workaround on the destination server: http://enable-cors.org/

sarge
  • 63
  • 1
  • 7
0

I found out that IIS 7.5 requires you to specify which domains are allowed to POST to the backend (see documentation). Basically I needed to add the following to the web.config file:

<configuration>
 <system.webServer>
   <httpProtocol>
     <customHeaders>
       <add name="Access-Control-Allow-Origin" value="*" />
     </customHeaders>
   </httpProtocol>
 </system.webServer>
</configuration>

With this all problems were solved!

dragon112
  • 137
  • 3
  • 9
0

I see you are using IIS. It also seems the URL you're trying to access to consume your web service is http://www.backenddomain.com/uploadhandler according to Chrome console (although is confuses me a bit that in the request headers you are posting when you try to upload there is an OPTIONS /main/uploadnetwork.php HTTP/1.1 - probably because you edited the info to hide the real address).

I encountered the same problem and the answer may be simpler than those above if your case is calling an URL without a explicit "somewhat.php" document at the end. If you are sure the address of the service is www.backenddomain.com/uploadhandler (http and all removed due to not having "enough reputation") and there is a default document being served there (I assume it is index.php), you have to append a trailing slash at the end of your address to call it.

So call the service at this address:

http://www.backenddomain.com/uploadhandler/

Pere
  • 101
  • 2