cordova cross domain request - html

I want to create a cordova generic client for debug purpose. but I face the cross domain request problem. My case is:
1. I deploy my source code (html code) on a web server A.
2. My backend data source is from server B.
3. I create a cordova app and run on the device or simulator. the App access the url from server A and open the app page, that work fine. but when my js code read data from Server B, all request is failed. I guess it's cause by cross domain restriction.
Any one have solution to resolve this problem?
Thanks!

Well, since your initial HTTP request goes through and HTML is returned, it seems that the connection from the Cordova is working, at least for server A.
What you could try is to upload temporarily "content" to server A which you try to fetch with AJAX calls.
If that succeeds, you can be sure that the fault is on server B and CORS works okay from front-end. In which case you could try to access the A & B from web client etc. to see possible differences in response headers. The server B is in that case probably missing Access-Control-Allow-Origin: * header. Try to add it to your server configuration or try JSONP. Also as a long shot, read your config.xml if you have only allowed connections to server A with
<access origin="<server A>"/>
in which case you obviously need to allow server B too.
If that fails, there is much less to work with and I can only suggest you to study resources like enable-cors.org which demonstrate how to actually allow CORS.

Related

How to fix axios.post without using package.json's proxy

The axios.post request doesn't work without proxy.
I am new in react js and using create-react-app
When I use proxy attribute in package.json and give it my http://url:port in my axios.post I start from /api/...
I do not need any config like headers or allow access. And I don't need to stringy data.
My back-end is java using Apache Tomcat and in back-end I have CORS filter that only allows application/json
requests. When I use postman if the header doesn't match , Apache refuses the request by 415 unsupported media type.
The problem begins from where I want to use npm run build. so there is no package.json and I should bring my full url to axios.post's url part : http://url:prot/api/..
Then I removed the proxy part from package.json
Since that I haven't seen any response from java or even it doesn't refuse the request in http monitoring or Apache Log part (in Netbeans)
I did two small things and something changed!
1-Adding JSON.stringfy before data
2-Adding headers Content-Type:Application/json
Now the request is observable in Netbeans (the back-end) BUT the messege is unsupported media type although i have added to axios.post's config(and itself caused the request received )!!!
there is some thing else : when I use the fire fox CORS enable adds on every things goes grate but only with that...
This is my first project. please explain like I'm 5! I do not know anything more!
Or if someone has any better way; is there any way i can use axios.post without package json proxy?

Simulate fake 404,500 Status Code to check frontend app behaviour

I want to simulate a fake 404 status code from the backend to see how my website will behave.
I don't want to mock fake response status in the code I would like to use some tools.
Cause sometimes I want to test it on the production which has version x and I don't want to waste time downloading this code and checking if there it is working.
Just simply mock response header status code for some test value like 404 for the fast check.
I tried to use software like Requestly - chrome extension.
And configured it like :
Modify response for header status put value 404 for google.com site.
But when I open google.com site I got status 200:
Do you know how can I change the status code of the given request?
Maybe by using different soft?
Status is not an HTTP response header. Status Code is an HTTP response code and Chrome does not allow to modify the response code of a request. There are two possible ways to solve this using Requestly
1-Step solution using Requestly Desktop App (Reliable & Guaranteed to work)
You can use any MITM proxy to intercept the request and simulate the status code. However, given my experience with Requestly, I'd explain how you can do it with Requestly Desktop App
Install Requestly Desktop App,
Go to Rules Tab and Click on New Rule
Select Modify Response
Define the exact URL (or Pattern) and define the status code. That's it.
Screenshot
Demo
https://www.youtube.com/watch?v=nLcIZGmMAtQ&ab_channel=Requestly
Using Requestly Browser Extension (2-Step Process, Should Work in most sites but there could be some CORS Issues)
Install Requestly
Use Requestly Mock Server and create a new mock which serves 400 or 404
Use Requestly to set up a Redirect Rule which redirects your original request to the URL of your mock request
Here are a couple of examples using the extension
Simulate 500 in Twitter Create Tweet API
Simulate 404 in BlinkIt Search API
Footer Notes
Desktop App-based solution is more reliable and guaranteed to work while Extension-based solution has technical limitations and there may be some CORS Issues depending upon your backend So prefer to use Solution 1.
PS - I built Requestly (& still building it with lots of heart)
In DevTools on the Network panel, right click a resource and select Block Request URL or Block Request Domain.
Does that help in your use case?
Try using ModResponse: https://chrome.google.com/webstore/detail/modresponse/bbjcdpjihbfmkgikdkplcalfebgcjjpm. You can add "Replay response" on the URL that you want to replay, visit that URL, then open up ModResponse again to edit the HTTP status code. You can also use it to edit the HTTP response body and header as well.

I can`t connect from Node-RED to Freeboard.io using JSON

I trying to create a freeboard dashboard. I have a Arduino with four sensors that send their informations by mqtt. So, I on Node-RED I gen a JSON to response get request in /saida.
[{"id":"3f699b5.c91f064","type":"http response","z":"c7d4e8c8.509218","name":"","x":1184,"y":589,"wires":[]},{"id":"a3ed6250.1d64","type":"json","z":"c7d4e8c8.509218","name":"","x":1120.5,"y":540,"wires":[["3f699b5.c91f064"]]},{"id":"971f41c1.a1265","type":"function","z":"c7d4e8c8.509218","name":"","func":"msg.payload = {\"temperatura\":\"25\"}\nreturn msg;","outputs":1,"noerr":0,"x":1015.5,"y":584,"wires":[["a3ed6250.1d64"]]},{"id":"ed9f7a2a.604728","type":"http in","z":"c7d4e8c8.509218","name":"http in","url":"/saida","method":"get","swaggerDoc":"","x":850,"y":582,"wires":[["5b40d38c.5cc7ec","971f41c1.a1265"]]}]
In this moment, I`m using a static JSON to make a test. I have a use the host like:
my-public-host:1880/saida -> {"temperatura":"25"}
I access it by a proxy, the JSON returns ok. On ping.eu port check, the port is open. I ensure that my host is public.
But on my freeboard, I add it as datasource, then it says "never" update and I can`t read the JSON info.
What I should do to solve it?
I solved my problem.
There is a bug in freeboard.io. the thingproxy.freeboard.io don't work. The the browser don't let the freeboard.io make AJAX request for other link that isn't https. Besides, the browser don't let make a AJAX request for an other host.
There is two solutions:
Use sitelock on your host and add Access-Control-Allow-Origin to you response headers.
Use a https proxy and a browser extension to allow cross access.
bye!
Correct.
If the data source is flask based app, you can follow this link below to make freeboard read.
https://flask-cors.readthedocs.io/en/latest/

How to set ServerCredential in Backgrounduploader in WinJS app

I called attached code below in WinJS app and keep getting this error 405 Method Not Allowed. I have changed the method property to "POST" , still the same thing. Some of the guys saying it is to do with the permission so I am trying to set the credential in the uploader. This is an internal app so we assume this should carry the Windows Authentication. But at the moment, I could not find how. Can anybody help?
uploader.createUpload(endpoint, file)
.startAsync()
You haven't narrowed down the problem to the point where you should be worrying about how to express what you need with BackgroundTransfer APIs yet - you need to figure out what you need to express, first.
If you have access to good documentation or a knowledgeable owner of this internal service you're connecting to, your first step should be consulting that to figure out what exactly the HTTP request (and the associated credential headers) should look like.
If you don't have access to that, the second best starting point is to take an existing, working client of this service you're uploading to and use a networking capture software (Fiddler, for example) to take a look at what the request it's sending looks like.
Once you've figured out the specific HTTP method and server credentials you need to use, you can tell BackgroundTransfer to use them by setting the method and serverCredential properties of your uploader object before creating your uploads.

Accessing redirected-to URL when making an HTTP request

When making an HTTP request (using URLLoader, for example) that results in a redirect, is it possible to access any of the URLs in the redirect chain?
For example, let's say that the following happens:
We make a request to example.com/a.gif
example.com redirects to example2.com/b.gif
example2.com redirects to example3.com/c.gif
I've stared at the documentation for URLLoader and its various events for a while, and it doesn't seem like there's a way to either:
Instruct URLLoader to not follow redirects
Access any of the URLs involved after the initial request
Does anyone know if there's a way to do this? I'm not attached to using URLLoader, so if there's another class that supports this functionality, I'd be fine with using it.
Can anyone point me in the right direction? Thanks in advance!
Edit - I should clarify: I know how to detect the redirects outside of AS3 using a DOM debugger. I'm specifically interested in accessing the redirect chain within AS3. It would appear that it's possible using the AIR player via the HttpStatusEvent, but the relevant properties aren't available when using Flash Player.
Edit 2 - I've also tried using an HTTP client lib (as3httpclientlib, to be specific). This works except for the fact that it loads cross-domain policies from port 843 rather than by making an HTTP request to /crossdomain.xml. The context I'm working in requires the latter, so using something with Socket underlying it won't work unless there's a way to force Socket to load cross-domain policies from HTTP instead of port 843.
The redirects are generally in place because the original URL shouldn't be used anymore. The file doesn't exist at example.com/a.gif so in theory you don't need to know about it. Why do you need the intermediate request path?
I'm not aware of an actionscript way of finding the redirect chain for any request, but if you want to do it for a specific chain you can use HttpFox for Firefox, or hit f12 in google chrome and look at the network tab when making a request to the URL that redirects. This will only work if the client is redirected by the server to the new address (a HTTP 302 responce or similar.) If the server chooses to return the contents of example3.com/c.gif when someone's browser asks for example.com/a.gif there is nothing you can do.