IIS URL Rewrite - Convert POST to GET - url-rewriting

In my application there is a client and a WCf REST service. For invoking some wcf service the client is doing an http POST even though the service is a GET.
i do not want to do any changes in the client or the service.
So is there a way where i can convert this POST request to GET and add the data coming in as the POST to the URL and invoke the REST service.
Thanks in advance.

You can use URL Rewrite to issue 3xx Redirect which will use GET method, but you will loose all POST data.
The only safe way known to me is to rewrite POST request to some another custom page, where you:
collect all POST data/variables;
convert them into GET variables (assemble proper GET request);
issue 301 (or 302) Redirect to the proper URL (it will have all POST data sent as GET variables).
Such rewrite to custom page should be easy -- you need to check what method is used (POST or GET) and only invoke it on POST. The rest will be handled in that post-to-get script.
The reason for all of this complexity is the difference in how POST and GET requests work: with GET all data is sent as part of URL while POST uses request body to transfer variable's data.

Related

Intercept HTTP Request in page

I am trying to make a scraper for a page of a supermarket. I noticed that this supermarket make API HTTP calls via AJAX, and if I enter to Inspect > Network then I can see the request headers of the calls I need.
Inside the requests headers there is an X-Token. If I use this X-Token with the URL via Postman I can get all the info in JSON format, which is better than scraping the web.
The problem is that this X-Token expires (I think, it still works). Is there any possibility to make a call to the page and "intercept" this API call in order to retrieve this X-Token and use it for the next custom requests?
I'am using Ruby on Rails :)

Web-api :-The requested resource does not support HTTP method 'POST' - Angular5

I can GET and POST from my Login apiController (so I can login/signup etc) but I can only GET from an API Controller in an area I have created. I get a 405 (Method Not Allowed)
Check the file you are posting to. Certain web servers, nginx, for example, returns a 405 if you POST to a static file. It's possible that IIS won't accept POST if there is no data payload.
See if your parameters are actually in the data/post part of the request. If your login parameters are in the URL query string, it's still a GET even though your method claims to be a POST. The server might reject empty POST requests.

Beego Redirect with Post method

I want to redirect the url using the POST method.
The code is usually using this.Redirect("/", 302).
This time, I want something like post url which should redirect to that page.
Is this possible with Beego?
Thanks.
Beego's Redirect takes a http code, you're just using the wrong one. You want 307 to force the request method to be the same as the original one.
this.Redirect("/", 307)
Most clients and browsers issue a GET on the 302 target, which was actually contrary to the RFC.
Due to this, 303 and 307 were introduced:
303: clients must use a GET request
307: clients must use the original method (eg: POST if a POST was originally used)

Cross domain issue due between https and http page. Ajax call failing

I have a website say xyz.com. i want to make an ajax call from say(http://pqr.xyz.com) to https://abc.xyz.com. but the call is failing to execute due to cross domain problem. Is there any method to overcome this. How xan i access the page via https.
If you want to make cross domain calls, you need to use JSONP.
This means you can change the server code so that the headers shows this cross-domain call is authorized. Depending on your server language, you'll have to do something like this :
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Request-Method", "GET")
w.Header().Set("content-type", "application/x-javascript") // this one of course for json calls
Using JSONP instead of JSON will also mean that you'll enclose you JSON in a function call, for example
acceptServerAnswer({'thisis':'myjson'])
Use a server-side proxy or JSON
http://devlog.info/2010/03/10/cross-domain-ajax

Ajax and a restricted uri

I would like to make an ajax call to a different server (same domain and box, just a different port.)
e.g.
My page is
http://localhost/index.html
I would like to make a ajax get request to:
http://localhost:7076/?word=foo
I am getting this error:
Access to restricted URI denied (NS_ERROR_DOM_BAD_URI)
I know that you can not make an ajax request to a different domain, but it seem this also included different ports? are there any workarounds?
Have a certain page on your port 80 server proxy requests to the other port. For example:
http://localhost/proxy?port=7076&url=%2f%3fword%3dfoo
Note the url encoding on the last query string argument value.
You could use JSONP. This is where you specify a callback with the request, the response from your ajax request gets wrapped with the callback function name. Rather than using XmlHttpRequest you insert a tag into the HTML document with the URL. Then when the response is retrieved the callback function is called, passing the data as a parameter.
Check this blog post out for an example
This is a browser restriction. All javascript calls must be to the same server and port of the home of the script. This will require something server-side to get around. I.E. have the process at localhost forward the request to localhost:7076.
It sucks, but it's necessary... Basically what you're going to need to do is proxy your AJAX request through a local proxy - some server side script / page / whatever on the same domain you're on - receive the call and forward it on to the other resource server-side. There might be some IFRAME tricks you could do but I don't think they work very well...could be wrong though, been awhile.

Resources