Questions tagged [uri]

A Uniform Resource Identifier (or URI) is a string of characters used to identify a name or resource. URI is legacy terminology. In most cases, the term URL should be used instead.

A Uniform Resource Identifier (or URI) is a string of characters used to identify a name or resource.

Note: The current URL Standard at https://url.spec.whatwg.org/#url-representation supersedes RFC 3986 and dispenses with the use of the term URI, as documented in its Goals section:

Standardize on the term URL. URI and IRI are just confusing. In practice a single algorithm is used for both so keeping them distinct is not helping anyone. URL also easily wins the search result popularity contest.

But the information below documents URI in terms of the legacy RFC 3986 spec.


Structure

A URI can be a Uniform Resource Locator , a Uniform Resource Name , or both.

RFC 3986 defines a URI as composed of the following parts:

    foo://example.com:8042/over/there?name=ferret#nose
    \_/   \______________/\_________/ \_________/ \__/
     |           |            |            |        |
  scheme     authority       path        query   fragment

Then defining relative URIs (Section 5.2), you can omit any of those sections, always starting from the left. In pseudo-code, it looks like this:

 result = ""

  if defined(scheme) then
     append scheme to result;
     append ":" to result;
  endif;

  if defined(authority) then
     append "//" to result;
     append authority to result;
  endif;

  append path to result;

  if defined(query) then
     append "?" to result;
     append query to result;
  endif;

  if defined(fragment) then
     append "#" to result;
     append fragment to result;
  endif;

  return result;

The URI you are describing is a scheme-less relative URI.

Examples

For example, in the following URI:

https://stackoverflow.com/questions/tagged/uri?sort=newest&pagesize=50#questions

... the components are:

  • scheme: https

  • hierarchical part: //stackoverflow.com/questions/tagged/uri

  • query: sort=newest&pagesize=50

  • fragment: questions

The precise syntax of the individual components varies depending on the scheme. Here are some examples:

  • mailto:nobody@example.com?subject=Hello&body=Is%20anybody%20home%3F

  • data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=

  • urn:ietf:rfc:3986

URL

A URL is a URI but is more specific. In addition to identifying a web resource, a URL specifies the means of acting upon or obtaining the representation, specifying both its primary access mechanism and network location.

For example, the URL http://example.org/wiki/Main_Page refers to a resource identified as /wiki/Main_Page whose representation, in the form of HTML and related code, obtainable via HyperText Transfer Protocol (http) from a network host whose domain name is example.org.

URI Reference

A URI reference may take the form of a full URI, or just the scheme-specific portion of one, or even some trailing component thereof – even the empty string. An optional fragment identifier, preceded by #, may be present at the end of a URI reference. The part of the reference before the # indirectly identifies a resource, and the fragment identifier identifies some portion of that resource.

To derive a URI from a URI reference, software converts the URI reference to 'absolute' form by merging it with an absolute 'base' URI according to a fixed algorithm. The system treats the URI reference as relative to the base URI, although in the case of an absolute reference, the base has no relevance. The base URI typically identifies the document containing the URI reference, although this can be overridden by declarations made within the document or as part of an external data transmission protocol. If the base URI includes a fragment identifier, it is ignored during the merging process. If a fragment identifier is present in the URI reference, it is preserved during the merging process.

Web document markup languages frequently use URI references to point to other resources, such as external documents or specific portions of the same logical document.

Uses of URI references in markup languages

  • In HTML, the value of the src attribute of the img element provides a URI reference, as does the value of the href attribute of the a or link element.
  • In XML, the system identifier appearing after the SYSTEM keyword in a DTD is a fragmentless URI reference.
  • In XSLT, the value of the href attribute of the xsl:import element/instruction is a URI reference; likewise the first argument to the document() function.

Examples of absolute URIs

Examples of URI references

6139 questions
151
votes
8 answers

Invalid URI: The format of the URI could not be determined

I keep getting this error. Invalid URI: The format of the URI could not be determined. the code I have is: Uri uri = new Uri(slct.Text); if (DeleteFileOnServer(uri)) { nn.BalloonTipText = slct.Text + " has been deleted."; …
anon271334
146
votes
9 answers

Get raw URL from Microsoft.AspNetCore.Http.HttpRequest

The HttpRequest class in Asp.Net 5 (vNext) contains (amongst other things) parsed details about the URL for the request, such as Scheme, Host, Path etc. I've haven't spotted anywhere yet that exposes the original request URL though - only these…
Jon Egerton
  • 40,401
  • 11
  • 97
  • 129
143
votes
26 answers

How to get the Full file path from URI

I'd like to get the full file path, from a URI. The URI isn't a Image, but it's a music file, but if i do it like the MediaStore Solution, it won't work if the app user selects eg Astro as browser, instead of Music Player. How do I solve this?
tim687
  • 2,256
  • 2
  • 17
  • 28
135
votes
9 answers

Get individual query parameters from Uri

I have a uri string like: http://example.com/file?a=1&b=2&c=string%20param Is there an existing function that would convert query parameter string into a dictionary same way as ASP.NET Context.Request does it. I'm writing a console app and not a…
Ghostrider
  • 7,545
  • 7
  • 30
  • 44
126
votes
7 answers

Converting of Uri to String

Is it possible to convert an Uri to String and vice versa? Because I want to get the the Uri converted into String to pass into another activity via intent.putextra() and if it's not possible can anyone suggest me a way how to pass selected Uri into…
NewDroidDev
  • 1,656
  • 5
  • 19
  • 33
126
votes
7 answers

Uri to default sound notification?

I use the Notification.Builder to build a notification. Now I want to use the default sound notification with: builder.setSound(Uri sound) But where is the Uri to the default notification?
StefMa
  • 3,344
  • 4
  • 27
  • 48
120
votes
8 answers

How to pass a URI to an intent?

I'm trying to pass a URI-Object to my Intent in order to use that URI in another activity. How do I pass a URI? private Uri imageUri; .... Intent intent = new Intent(this, GoogleActivity.class); intent.putExtra("imageUri",…
Robert El
  • 1,247
  • 2
  • 10
  • 10
120
votes
9 answers

How to construct a WebSocket URI relative to the page URI?

I want to construct a WebSocket URI relative to the page URI at the browser side. Say, in my case convert HTTP URIs…
neuront
  • 9,312
  • 5
  • 42
  • 71
118
votes
4 answers

Convert a file path to Uri in Android

I have an app where I capture a video using the camera. I can get the video's file path, but I need it as a Uri. The file path I'm getting: /storage/emulated/0/DCIM/Camera/20141219_133139.mp4 What I need is like…
Vinodh Kumar
  • 1,457
  • 2
  • 10
  • 17
118
votes
7 answers

What's valid and what's not in a URI query?

Background (question further down) I've been Googling this back and forth reading RFCs and SO questions trying to crack this, but I still don't got jack. So I guess we just vote for the "best" answer and that's it, or? Basically it boils down to…
John Leidegren
  • 59,920
  • 20
  • 131
  • 152
110
votes
8 answers

how to get an uri of an image resource in android

I need to open an intent to view an image as follows: Intent intent = new Intent(Intent.ACTION_VIEW); Uri uri = Uri.parse("@drawable/sample_1.jpg"); intent.setData(uri); startActivity(intent); The problem is that Uri uri =…
user602874
  • 1,429
  • 2
  • 12
  • 10
110
votes
6 answers

What's the difference between Uri.Host and Uri.Authority

System.Uri has Host, Authority, and DnsSafeHost. MS provides a nice example of when Host and DnsSafeHost are different here. I'd like a similar example/explanation for Host and Authority.
Brian
  • 25,523
  • 18
  • 82
  • 173
108
votes
7 answers

How I can get the mime type of a file having its Uri?

I have a List of Uris obtained with the Gallery and the Camera. These Uris are like this: content://media/external/images/media/94. How I can get its mime type?
Brais Gabin
  • 5,827
  • 6
  • 57
  • 92
105
votes
8 answers

File Uri Scheme and Relative Files

Assume that the scheme for a uri is "file". Also assume that the path starts with '.' An example path is './.bashrc'. How would the fulluri look? 'file://./.bashrc' appears odd to me.
user592419
  • 5,103
  • 9
  • 42
  • 67
103
votes
6 answers

How to check that a uri string is valid

How do you check that a uri string is valid (that you can feed it to the Uri constructor)? So far I only have the following but for obvious reasons I'd prefer a less brute way: Boolean IsValidUri(String uri) { try { …
Manuel
  • 10,869
  • 14
  • 55
  • 86