× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



...my mailer may have trashed all the URLs in that last post, in which case let me know and I will repost with them cleaned up.


________________________________
From: WEB400 <web400-bounces@xxxxxxxxxxxx> on behalf of Tim Fathers <X700-IX2J@xxxxxxxxxxx>
Sent: 06 December 2018 22:34
To: Web Enabling the IBM i (AS/400 and iSeries)
Subject: Re: [WEB400] Header set Access-Control-Allow-Origin for web services

Good question, it depends on what you're struggling with but, as a long time RPG programmer I have been through the pain you currently find yourself in, so I will do my best to explain if I can.

If I understand your case correctly you have two servers running on your IBM i:

https://nam05.safelinks.protection.outlook.com/?url=http%3A%2F%2Fi.server.com%3A10000%2Fweb%2Fservices%2FOceans&amp;data=02%7C01%7C%7C64bd292e781d479d6ee708d65bc2a479%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636797288867230668&amp;sdata=p8x4EyjhfUHq334%2BFsnrlfRaulb6gIr6ZaUAuahBnlo%3D&amp;reserved=0 which is your experimental web service
https://nam05.safelinks.protection.outlook.com/?url=http%3A%2F%2Fi.server.com%3A80%2F&amp;data=02%7C01%7C%7C64bd292e781d479d6ee708d65bc2a479%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636797288867230668&amp;sdata=vqf44opITL9751UjsyN%2FNdqocHCYGFS6jIwAsKvibI8%3D&amp;reserved=0 which is your web server serving up your HTML/Javascript pages (I've assumed port 80)

When you visit your website (port 80), it serves up some HTML and Javascript, which attempts to make an AJAX request back to the web service (port 10000), but this is not allowed because the AJAX request is not to the same origin (the port is different), so you get an error. The trick is to hide your web service behind the web server so that both your web pages and your web service appear to be hosted at the same place, you can do this by configuring certain paths on your web server to reverse proxy requests to the web service. The basic concept of reverse proxying is fairly simple to understand, it's just the web server saying "I don't know how to handle this URL, but I know someone who does so I'll forward it there and send you back the result when I get it". So, you might set-up the following path on the web server (port 80) to proxy to the web service (notice you can map any path on the web server to any URL):

/webservice/oceans --> http://localhost:10000/web/services/Oceans

Now any request you make to the following address https://nam05.safelinks.protection.outlook.com/?url=http%3A%2F%2Fi.server.com%3A80%2Fwebservice%2Foceans&amp;data=02%7C01%7C%7C64bd292e781d479d6ee708d65bc2a479%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636797288867230668&amp;sdata=7Fw3lP1rGD%2F%2F3whjKbRbbca%2BLv2485Sru8QTaQQTO78%3D&amp;reserved=0 will be forwarded to the web service on the same server on port 10000 (you can test this with the browser). This includes any children of that path, so:

https://nam05.safelinks.protection.outlook.com/?url=http%3A%2F%2Fi.server.com%3A80%2Fwebservice%2Foceans%2Fcustomers&amp;data=02%7C01%7C%7C64bd292e781d479d6ee708d65bc2a479%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636797288867230668&amp;sdata=TP6iDRUl1aeW0r41Bw4npAZoaHywQRRN7v805TDy7ug%3D&amp;reserved=0 ----forwards to----> https://nam05.safelinks.protection.outlook.com/?url=http%3A%2F%2Fi.server.com%3A10000%2Fweb%2Fservices%2FOceans%2Fcustomers&amp;data=02%7C01%7C%7C64bd292e781d479d6ee708d65bc2a479%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636797288867230668&amp;sdata=FMpyIlS2a4920gA7g6CibZcBZk%2BtgeWm69UYzZ9HNGo%3D&amp;reserved=0
https://nam05.safelinks.protection.outlook.com/?url=http%3A%2F%2Fi.server.com%3A80%2Fwebservice%2Foceans%2Fcustomers%2F1%2Forders%2F3&amp;data=02%7C01%7C%7C64bd292e781d479d6ee708d65bc2a479%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636797288867230668&amp;sdata=%2FpkJjbn10fiUjyLsEuI%2BxvVpvadrZKVK9S%2BqI9CpIIg%3D&amp;reserved=0 ----forwards to----> https://nam05.safelinks.protection.outlook.com/?url=http%3A%2F%2Fi.server.com%3A10000%2Fweb%2Fservices%2FOceans%2Fcustomers%2F1%2Forders%2F3&amp;data=02%7C01%7C%7C64bd292e781d479d6ee708d65bc2a479%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636797288867230668&amp;sdata=bDquK53DgmGfqjAXNpA6VvLK0%2BZ558DxtaXe0RFBnMY%3D&amp;reserved=0
etc.

Now, you need to change your Javascript too because this will still have the full URL of the web service in the address and thus be still pointing to port 10000, so the above changes will not have yet made any difference. Instead of using absolute URLs in your AJAX requests (e.g. GET https://nam05.safelinks.protection.outlook.com/?url=http%3A%2F%2Fi.server.com%3A10000%2Fweb%2Fservices%2FOceans%2Fcustomers%2F1&amp;data=02%7C01%7C%7C64bd292e781d479d6ee708d65bc2a479%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636797288867230668&amp;sdata=hnlkguEbhJmZqBgig3UdXz8SSXY5PuICSBRm%2Bk6GSCY%3D&amp;reserved=0) you need to use relative URLs that point to the path you have mapped above (e.g. GET /webservices/Oceans/customers/1). Now your AJAX requests go back to the same server that served up the page they are embedded in so the same origin policy is respected, the web server sees the path /webservice/oceans and says "Ah, I have to forward this request to https://nam05.safelinks.protection.outlook.com/?url=http%3A%2F%2Fi.server.com%3A10000%2Fweb%2Fservices%2FOceans%2F&amp;data=02%7C01%7C%7C64bd292e781d479d6ee708d65bc2a479%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636797288867230668&amp;sdata=AyvTQxmqoAs7m%2BuNdZ3RylkL7QdJX1%2FnXpQz6mvDGGw%3D&amp;reserved=0 and then when I get a result, send it back").

Setting it up on the IBM I HTTP server is quite easy, go to the admin panel at https://nam05.safelinks.protection.outlook.com/?url=http%3A%2F%2Fi.server.com%3A2001%2FHTTPAdmin&amp;data=02%7C01%7C%7C64bd292e781d479d6ee708d65bc2a479%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636797288867230668&amp;sdata=nVI3mKcYTRdzUyQSCzT8gR0aVneMEQWCvzWRwOHd32g%3D&amp;reserved=0 and log in (you need *ALLOBJ or to be added to authority table to do this). Make sure you select your *web* server and then go to the "proxy" option in the left menu. When you get there, click the "Reverse Proxy" tab and make sure "Reverse proxy capabilities" is Enabled. Then, under "Proxy requests to remote servers:" add your mapping (for example):

"Client requests" "/webservice/oceans" "localhost:10000/web/services/Oceans"

save, apply and then restart the server.

Now, pointing your broswer at https://nam05.safelinks.protection.outlook.com/?url=http%3A%2F%2Fi.server.com%3A80%2Fwebservice%2Foceans%2F&amp;data=02%7C01%7C%7C64bd292e781d479d6ee708d65bc2a479%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636797288867230668&amp;sdata=QTDB7dYtBqebHca1VmNbxuLgwBjV5gUM%2F1wDJHC3mlA%3D&amp;reserved=0<web-service> should give you back something from your web service.

Tim.





________________________________
From: WEB400 <web400-bounces@xxxxxxxxxxxx> on behalf of Booth Martin <booth@xxxxxxxxxxxx>
Sent: 06 December 2018 19:19
To: Web Enabling the IBM i (AS/400 and iSeries)
Subject: Re: [WEB400] Header set Access-Control-Allow-Origin for web services

Is there a place that uses explanations and examples that would be
meaningful to an RPG programmer (The Target Audience for the IWS Wizard)?

On 12/6/2018 3:59 AM, Tim Fathers wrote:
If your web server is on a different port than your web service then it will also fail the "same-origin" policy test (see here https://nam05.safelinks.protection.outlook.com/?url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FSame-origin_policy&amp;data=02%7C01%7C%7C64bd292e781d479d6ee708d65bc2a479%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636797288867230668&amp;sdata=AYBV0GyaC7SgpgUF%2FyGf1JNQ0FF2eB%2BQps2%2FPswsIEo%3D&amp;reserved=0).

As I mentioned before, IMO you are better not to mess around with CORS but to forward proxy the web app requests from the HTTP server to the web service. In other words, set-up a forward proxy rule in your web server that says

/web/services ---> localhost:10000/web/services/Oceans

...then change your AJAX requests to be relative to the current host e.g. "/web/services/Oceans/get....". Because these requests are to the same origin you won't fall foul of the same origin policy and your web server will make sure the request gets routed to your Oceans application server.

Tim.

Same-origin policy - Wikipedia<https://nam05.safelinks.protection.outlook.com/?url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FSame-origin_policy&amp;data=02%7C01%7C%7C64bd292e781d479d6ee708d65bc2a479%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636797288867230668&amp;sdata=AYBV0GyaC7SgpgUF%2FyGf1JNQ0FF2eB%2BQps2%2FPswsIEo%3D&amp;reserved=0>
In computing, the same-origin policy is an important concept in the web application security model.Under the policy, a web browser permits scripts contained in a first web page to access data in a second web page, but only if both web pages have the same origin.An origin is defined as a combination of URI scheme, host name, and port number.
en.wikipedia.org






________________________________
From: WEB400 <web400-bounces@xxxxxxxxxxxx> on behalf of Booth Martin <booth@xxxxxxxxxxxx>
Sent: 05 December 2018 19:52
To: Web Enabling the IBM i (AS/400 and iSeries)
Subject: Re: [WEB400] Header set Access-Control-Allow-Origin for web services

I believe the following is an accurate report:

* The i is remote, reached by VPN. Lets call
"i.server.com:10000/web/services/Oceans" TheURL. This is a web
service providing a short list of 5 oceans from QMYLIB/OCEANSP.
* There is also an HTTP server set up on the TheURL's domain with a
website using JavaScript. That JavaScript presents a web page with
a nicely formatted layout and attempts to retrieve the Oceans data
from TheURL. It fails with the CORS failure.
* Eclipse is installed on my PC and the same JavaScript set-up is
installed there, pointing at TheURL. It fails with the CORS failure.

If I point my regular browser at TheURL i immediately get the 5 oceans
returned to me. Both JavaScript installations give me the CORS
failure. In other words, any regular web browser inside the VPN can
easily retrieve the data, but a JavaScript server at the same domain is
blocked???

Thats just ridiculous; therefore, I am misunderstanding something.



On 12/5/2018 12:15 PM, Justin Taylor wrote:
Sounds like cross-site scripting. By default, JavaScript (JS) is prevented from calling servers other than the origin server that served the initial page.

Is you JS trying to call a different server?
--
This is the Web Enabling the IBM i (AS/400 and iSeries) (WEB400) mailing list
To post a message email: WEB400@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://nam05.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.midrange.com%2Fmailman%2Flistinfo%2Fweb400&amp;data=02%7C01%7C%7C64bd292e781d479d6ee708d65bc2a479%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636797288867230668&amp;sdata=3OJ6kNYeYj10WyxfH1ejQ1CllGd%2B%2FSUNuysDHd2Gd3M%3D&amp;reserved=0
or email: WEB400-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://nam05.safelinks.protection.outlook.com/?url=https%3A%2F%2Farchive.midrange.com%2Fweb400&amp;data=02%7C01%7C%7C64bd292e781d479d6ee708d65bc2a479%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636797288867230668&amp;sdata=5pjDm3absm6Z93YNaoWby61EoKqBJ%2FOBifhvZyMrqmg%3D&amp;reserved=0.

--
This is the Web Enabling the IBM i (AS/400 and iSeries) (WEB400) mailing list
To post a message email: WEB400@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://nam05.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.midrange.com%2Fmailman%2Flistinfo%2Fweb400&amp;data=02%7C01%7C%7C64bd292e781d479d6ee708d65bc2a479%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636797288867230668&amp;sdata=3OJ6kNYeYj10WyxfH1ejQ1CllGd%2B%2FSUNuysDHd2Gd3M%3D&amp;reserved=0
or email: WEB400-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://nam05.safelinks.protection.outlook.com/?url=https%3A%2F%2Farchive.midrange.com%2Fweb400&amp;data=02%7C01%7C%7C64bd292e781d479d6ee708d65bc2a479%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636797288867230668&amp;sdata=5pjDm3absm6Z93YNaoWby61EoKqBJ%2FOBifhvZyMrqmg%3D&amp;reserved=0.

--
This is the Web Enabling the IBM i (AS/400 and iSeries) (WEB400) mailing list
To post a message email: WEB400@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://nam05.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.midrange.com%2Fmailman%2Flistinfo%2Fweb400&amp;data=02%7C01%7C%7C64bd292e781d479d6ee708d65bc2a479%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636797288867230668&amp;sdata=3OJ6kNYeYj10WyxfH1ejQ1CllGd%2B%2FSUNuysDHd2Gd3M%3D&amp;reserved=0
or email: WEB400-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://nam05.safelinks.protection.outlook.com/?url=https%3A%2F%2Farchive.midrange.com%2Fweb400&amp;data=02%7C01%7C%7C64bd292e781d479d6ee708d65bc2a479%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636797288867230668&amp;sdata=5pjDm3absm6Z93YNaoWby61EoKqBJ%2FOBifhvZyMrqmg%3D&amp;reserved=0.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.