I am writing a code to get through authentication to a API based web site. I have the API key that the site needs during the login process. When I call the login method with the API key, it is supposed to redirect to a predefined URL whose parameter will then contain the request token.
e.g on firing the URL in the browser,
https://kite.trade/connect/login?api_key=hcwmefsivttbchla
I am redirected to
https://impacted-purposes.000webhostapp.com/?status=success&request_token=nb0vrfota9ott1r02q153pk3422joruf
(The request token will change in every run)
Notice the request token in the URL on the redirected URL. That's what I need to get from the code.
So, I use a the code that is referred here GetFinalRedirect:
Getting the Redirected URL from the Original URL
ie. I call:
GetFinalRedirect("https://kite.trade/connect/login?api_key=hcwmefsivttbchla")
However, I don't get the final redirect. I understand there could be a Javascript redirect, but checking the response, doesn't suggest so.
Any help pls to get the final URL so that I can parse the request token from it.
Well, I can't test this since i don't have an account. And I hope thats not your real-api-key...
But the function you're using is just sending a HEAD request to server. A HEAD request has no response. With the HEAD request you will only get redirects that are included in the HTTP headers. If the redirect is done with HTML-META tags or with javascript you have to send a GET (or POST) request...
If that fails too set a breakpoint inside the function and look at the received http-headers and the response text...
Related
I am attempting to generate a pdf from a SSRS report using URL Access in C#.
(In the business layer behind a WebApi Controller) I create an instance of the HttpClient, assign correct credentials and form the request URL like:
http://sqlserver1/ReportServer/Pages/ReportViewer.aspx?/Clients/Acme/AcmeActivitySummary&rs:Command=Render&rs:format=pdf&Region=west&CutOffDate=10/25/2015
If I put my URL in a browser, it downloads the expected PDF file.
When I execute this URL from the HttpClient instance to return a stream, I get a 401 Unauthorized Error.
If I open up Fiddler to see why...it works as expected.
How do I make this work without having to use Fiddler...and why doesn't it work now?
Somewhere along the lines Microsoft changed the "standard" for URL Access to SSRS. The URL Pattern " http://{Server}/ReportServer/Pages/ReportViewer.aspx?/{Path to Report File} & [commands] & [parameters]
was deprecated in favor of
http://{server}/reportserver?/{path} & [commands] & [parameters].
HOWEVER...the old url pattern will still work 'sometimes'. SSRS will still receive the request at the old 'endpoint' and, if the request can be forwarded it will do so. So a 'normal' request from a browser (or from Fiddler) appears to work just fine. The problem is with the HttpClient request, which SSRS will not forward to the new endpoint...and it just returns the [somewhat confusing] 401 Unauthorized exception...which apparently means "I am not authorized to forward this request" not "you are not authorized to access this resource".
(after losing more time than I care to admit finding this...I thought a post here would be helpful to others.)
I am new at web development, so how to make http request\respone for some site (http://google.com)
Thank you!
P.S.
I mean, that when my SomeController activated- i want send http request to another site,get data from it and send it into View
A client (browser) submits HTTP request to the server; then the server returns a response to the client. The response contains status information about the request and also contains the requested content. GET - requests data from a specified resource, http://google.com - you type this url in browser and hit the enter key, it's a get request and you see a page, that the response.
Click here for details.
Use HttpClient to connect a site from your mvc controller, click here for details.
I want to redirect from www.abc.com to www.xyz.com.
When I redirectd to www.xyz.com at that time how I know about details of GET method of HTTP . so that I come to know this request come from www.abc.com.
As both application hosted on different sever. I tried HTTP Handler for www.xyz.com, but I am unable to get details of HTTP when request method is GET. My handler and module event unable to call at time of redirect.
You can pass hint, for example a parameter saying returnURL=abc.com.
And in the XYZ.com, check for the URL parameter.
Usually when you redirect the request, your header will have the Referrer information which can be retrievable from the target server. For more details about HTTP Referrer please click here
I've come across something that's puzzled me for the past 3 hours regarding Facebook's login procedure.
I visited http://m.facebook.com (with UA Spoofer installed and set to Nokia Lumia User-Agent) and proceeded to log-in whilst monitoring the headers. I purposely entered the wrong password for an account I have.
When pressing log-in it sends a POST request to this URL: https://m.facebook.com/login.php?refsrc=http%3A%2F%2Fwww.facebook.com%2F&refid=8 the status code returns a 200 response code.
Then instantly afterwards it does a GET request to this URL: http://m.facebook.com/login.php?refsrc=http%3A%2F%2Fwww.facebook.com%2F&refid=8&e=1348022&email=frankthebutcher%40hotmail.com&signup_layout=layout%7Cbottom_clean%7C%7Cwider_form%7C%7Cprmnt_btn%7Cspecial%7C%7Cst%7Ccreate%7C%7Cheader_button%7C%7Chdbtn_color%7Cgreen%7C%7CFeb1&li=jFMuUdDWbmFhq8b-zAjEOHnE&_rdr
Which is the URL that says the password was incorrect.
But, where is that redirect coming from? There is nothing in the response headers from the first POST request, and JavaScript isn't enabled.
Try it on Chrome. Would love to know how it's doing that so I can adjust the mobile app I'm developing accordingly.
Solved: In my mobile app I was sending the POST request to the right URL, but the URL string I used was encoded which was causing the problem.
The first POST request is sending back a Location header which tells the browser to step-ahead from this request and proceed with the next. The second request is just the browser then using that new Location supplied and moving forward.
here's what you see from the first POST response:
However, from what I can see it's a 302 (redirection: found) response, not a 200 OK. Something tells me that you're judging the response headers on the final request, not the intermediate redirect/handoff.
i am sending a request to ajaxhandler
i want if the user is not logged in then it sends back a redirect url to login page
and the page automaticaly redirects to login page after the ajaxrequest response
We do this by just passing the url along in a JSON response then just having the AJAX handler check for it and set the location, however this might pose a security issue, you might just want to send back a flag or something and keep the url on the client-side.
i have a idea that
sending request using json
in json return the redirect url and when you get json result then redirect to specific page