Strange issue about # in url - url

http://localhost/test/editformquestions.php#?formid=1
And
http://localhost/test/editformquestions.php?formid=1
I failed to retrieve $_GET['formid'] in the first one,why?
The content of test/editformquestions.php is simply:
<?php
echo $_GET['formid'];
?>

Characters after the hash # are to be used by the browser, they are not sent back to the server.

# is a hash character, not a GET variable.
You need to put the ? before any hashes, otherwise the $_GET array will not be populated.

# is used by the browser, and is never sent to the server. Everything after a # (regardless of what it is) is used by the browser to jump to a location on the page.
So:
http://localhost/test/editformquestions.php#?formid=1
Will be split as follows:
Server request to http://localhost/test/editformquestions.php
Browser then searches in page for:
<a name="?formid=1">named anchor tag</a>
What you should do is:
http://localhost/test/editformquestions.php?formid=1&othervar=2#anchorinpage
Or, if you need the # in a query-string parameter:
http://localhost/test/editformquestions.php?formid=1&othervar=textwith%23init

The # is fragment identifier for a URL: http://en.wikipedia.org/wiki/Fragment_identifier
To use it as part of an array variable you'll need to url encode it:
'#' becomes '%23' when url-encoded
In javascript you can accomplish url encoding with the encodeURI() function

A HTTP URL may contain these parts:
protocol: http://
domain: localhost
path: /test/editformquestions.php
query string: ?formid=1 - always starts with a ?
fragment: #something - always starts with a # - whatever comes after the # mark is NOT sent to the server.
What you have in your first example (http://localhost/test/editformquestions.php#?formid=1) is a fragment containing this: #?formid=1. It does not matter that there's a ? in the fragment; as soon as it's behind the #, it is not sent from the browser.
So, in essence, you are sending to the server only this: http://localhost/test/editformquestions.php - as you can see, there is no formid in that request.

Related

Getting parameters from IdHTTPServer - Firemonkey

I’m trying to get Dropbox token from call-back parameters but the parameters are always empty.
Here is my code:
sURL :=
https://www.dropbox.com/oauth2/authorize' +
'?response_type=token' +
'&client_id=' + MyAppID +
'&redirect_uri=http://127.0.0.1:8888/';
ShellExecute(0, 'OPEN', PChar(sURL), '', '', SW_SHOWNORMAL);
Next I have IdHTTPServer set to listen http://127.0.0.1:8888/ address.
On executing the browser with Dropbox log-in popup. When I made log-in the redirection is made and the “IdHTTPServerCommandGet” events is called. So far so good.
In the browser I can see the next URL:
http://127.0.0.1:8888/#access_token=123&token_type=bearer&uid=1234&account_id=dbid%1234
But in “IdHTTPServerCommandGet” events the parameters are always empty:
ARequestInfo.UnparsedParams; // Empty
ARequestInfo. QueryParams; // Empty
if ARequestInfo.Params.Count > 0 then // Empty
sToken := ARequestInfo.Params[0];
And here is my question. How can I get the whole URL with parameters from IdHTTPServer?
Look very closely at the redirect url you are seeing in your browser. All of the parameters you want to access are after a # character, not a ? character. That puts them in the "fragment" portion of the url rather than the "query" portion. A web browser does not include a url's "fragment" in an HTTP request to a web server. That is why the TIdHTTPRequestInfo properties are empty - the parameters are literally not being sent to your TIdHTTPServer. The redirected url needs to put the parameters in the url's "query" instead. That is Dropbox's responsibility to handle correctly on its end.
That being said, you don't actually need the TIdHTTPServer at all, if you use an embedded web browser directly in your app, such as Delphi's TWebBrowser. You can hook into the embedded browser to catch the redirect directly, and all of the data that is in the redirected url. This also allows you to use a custom url scheme for the redirect url, you don't have to use "http(s):" (see Redirect URLs for Native Apps).

Unable to URL encode { } for object filters in softlayer REST URI

I am calling a Get method through Rest and my URI contains { } for object filters in Softlayer. I have used %7B for { and %7D for }, but I get java.net.URISyntaxException.
The URI also contains # which I have replaced with %40. This is working. I am using http Client to execute my Rest Call. The URI works fine on Postman, both with and without URL Encoding.
Here two way to skip or handle #:
how is '#' handled in the softlayer Rest calls
Another way to skip special characters would be, using "\" at the start from any of these chars, here an example of this:
SoftLayer getUsers by userStatusID
Also, it's necessary to skip {}": (special chars in objectFilters), if you are continue hitting with the exception, would be great if you could provide an example or the exactly code that you are trying, for further assistance
How to get Virtual Guests for a specific datacenter
Here a rest request for dal05 datacenter:
https://api.softlayer.com/rest/v3/SoftLayer_Account/getVirtualGuests?objectMask=mask%5Bid%2Chostname%5D&objectFilter=%7B%22virtualGuests%22%3A%7B%22datacenter%22%3A%7B%22name%22%3A%7B%22operation%22%3A%22dal05%22%7D%7D%7D%7D

How to get the page origin in razor?

I'm looking for the equivalent of this javascript
window.location.origin
but server side, while building mvc pages.
For example, if you are here
http://website.com/123,
it would return
http://website.com
Its important that i have the "http://" part
I'm a fan of
string url = Request.Url.PathAndQuery.length > 1
? Request.Url.AbsoluteUri.Replace(Request.Url.PathAndQuery, string.Empty)
: url;
Keeps your Http/Https, Port (if applicable), and HostName/IP.
DotNetFiddle Examples
Updated to Account for PathAndQuery length of 1.
you could try
#String.Format("{0}://{1}", Request.Url.Scheme, Request.Url.Authority)
Or
#String.Format("{0}://{1}", Request.Url.Scheme, Request.Url.Host)
Authority will include the port number
I think you looking for Request.Url or RawUrl.
Uri.Scheme of Request.Url will give you info on http/https difference.
The window.location.origin in javascript returns the protocol, port (if any), domain and extension of the current url.
If you want to get the same information from an URL, the accepted answers will provide that to you.
If you want the same behavior, ie a piece of javascript is calling your server method and you want to know where it is calling from, you can inspect the HttpRequest.URLReferrer. However this can be spoofed easily and thus is not reliable.

How to debug HTTP AUTH params in Rails?

Rubyists,
something's wrong with my HTTP AUTH params that are coming into my Rails 3 app. The password has some whitespace at the end. I was debugging my client app and it looks like it is sending it correctly.
I am doing this in my app:
params[:auth_username], params[:auth_password] = user_name_and_password(request)
Then I am sending this into Warden.
I would like to see the raw data to see if the whitespace is there. How to do that?
Edit: I have debugged the wire between httpd and thin process and I am pretty sure the data are coming correctly. It must be something wrong in my Rails 3.0.10. I was able to decode the base64 string that is coming in the headers and it did not contain any whitespace.
This really looks like BASE64 decoder issue. Maybe a padding problem. My string is:
Qmxvb21iZXJnOnRjbG1lU1JT
which decodes to
Bloomberg:tclmeSRS
correctly using non-Ruby base64 decoders. Even in Ruby:
>> Base64.decode64 "Qmxvb21iZXJnOnRjbG1lU1JT"
=> "Bloomberg:tclmeSRS"
I don't get it. Searching for a bugreport in Rails or something like that.
Edit: So it turns out our Apache httpd proxy adds something to the header:
Authorization: Basic Qmxvb21iZXJnOnRjbG1lU1JT, Basic
This leads to the incorrect characters at the end of the password, because:
>> Base64.decode64('Basic Qmxvb21iZXJnOnRjbG1lU1JT, Basic'.split(' ', 2).last || '')
=> "Bloomberg:tclmeSRS\005\253\""
The question is now - is this correct? Is it a bug in httpd or rails?
Rails user_name_and_password method makes a call to decode_credentials that performs the following, then splits using ":" :
::Base64.decode64(request.authorization.split(' ', 2).last || '')
Applied to your data :
::Base64.decode64("Qmxvb21iZXJnOnRjbG1lU1JT".split(' ', 2).last || '').split(/:/, 2)
=> ["Bloomberg", "tclmeSRS"]
Everything seems to be ok, the problem sits elsewhere IMO. To dump the authorization data from your controller :
render :text => "Authorization: #{request.authorization}"

Retrieving the url anchor in a werkzeug request

I have a DAV protocol that stores out-of-band data in the url anchor, e.g. the ghi in DELETE /abc.def#ghi. The server is a Flask application.
I can see the request come in on the wire via tcpdump, but when I look at the werkzeug Request object (such as url() or base_url()), all I get back is /abc.def. The #ghi has been stripped out.
Is there a method that returns this information, or do I have to subclass Request to handle this myself? If so, is there an example I can use as an inspiration?
I ran into the same problem. Facebook authentication API returns the access token behind a hash appended into the redirection url. In the same way, Flask's request.url drops everything in the URL behind the hash sign.
I'm also using Flask so I think you can use my brute-force workaround using Javascript's window.location.href to get the full URL. Then, I just extracted the piece that I needed (the access token), put it into a redirection URL where I can pass the access token as an argument to the receiving view function. Here's the code:
#app.route('/app_response/<response>', methods=['GET'])
def app_response_code(response):
return ''' <script type="text/javascript">
var token = window.location.href.split("access_token=")[1];
window.location = "/app_response_token/" + token;
</script> '''
#app.route('/app_response_token/<token>/', methods=['GET'])
def app_response_token(token):
return token
In case you manage(d) to do this within Werkzeug, I'm interested to know how.
From Wikipedia (Fragment Identifier) (don't have the time to find it in the RFC):
The fragment identifier functions differently than the rest of the URI: namely, its processing is exclusively client-side with no participation from the server
So Flask - or any other framework - doesn't have access to #ghi.
You can do this using flask.url_for with the _anchor keyword argument:
url_for('abc.def', _anchor='ghi')

Resources