Raj
Raj

Reputation: 69

HTTP 405 method not allowed, seems to be a CORS issue

Requested this URL from my Javascript program (has library epson-2.6.0.js, epson sdk for javascript for thermal printers). I am targeting a TM U220 over ethernet.

GET XHR http://192.168.199.15:8008/socket.io/1/

OPTIONS XHR http://192.168.199.15/cgi-bin/epos/service.cgi   [HTTP/1.1 405 Method Not Allowed 7ms]

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://192.168.199.15/cgi-bin/epos/service.cgi?devid=local_printer&timeout=10000. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

Response headers (118 B)

Allow   GET, HEAD, POST
Content-Length  0
Server  Allegro-Software-RomPager/4.01

Request headers (478 B)

Accept  text/html,application/xhtml+xm…plication/xml;q=0.9,*/*;q=0.8
Accept-Encoding gzip, deflate
Accept-Language en
Access-Control-Request-Headers  content-type,if-modified-since,soapaction
Access-Control-Request-Method   POST
Connection  keep-alive
DNT 1
Host 192.168.199.15
Origin  null
User-Agent  Mozilla/5.0 (Windows NT 10.0; …) Gecko/20100101 Firefox/58.0

I have been searching all over the Internet on how to solve this issue. Somebody please help. I Cannot change the printer firmware for the http server and can only do something from the Javascript I control.

Upvotes: 2

Views: 3830

Answers (2)

Simon Cabotse
Simon Cabotse

Reputation: 11

You need to enable ePos Webservices.

This cannot be done using the executable utilities provided. Once your printer is connected to the network with a valid local IP, you need to browse http://192.168.199.15 (or whatever your epson printer IP is) with your usual browser, it will ask you for user password which default to epson/epson OR epson/printer serialNb then you need to navigate to ePos print, and then enable the option ePos Print, finaly click the restart button just underneath. Then the printer will add an Allow-Cross-Origin * header to the HTTP response headers, which is good, and no need to disable usefull browser feature.

Upvotes: 5

cdoshi
cdoshi

Reputation: 2832

There are a few ways to solve the CORS issue if you do not have control over the server.

Method 1.

Install the CORS plugin https://chrome.google.com/webstore/detail/cors-toggle/jioikioepegflmdnbocfhgmpmopmjkim?hl=en

This would be useful if your application is made only for you and would not be used by anyone else. Also, some websites like youtube would stop working so use with caution

Method 2.

Create your own proxy server. Recommended but needs technical know how. This solution is especially useful if your application is used by lot of other users too. This is something I have done before and has worked well. You can host your proxy server on heroku or anywhere you want. Your proxy server would intercept the OPTIONS request and would send Access-Control-Allow-Origin: * in response headers thus enabling your browser to make a get/post call. Your proxy server would then route your request to the actual server and return the response from the actual server back to the client

Upvotes: 0

Related Questions