Change path of gapi.client.request from relative to absolute - google-api-js-client

I want to use a refresh token to generate an access token. So I am making a gapi.client.request as shown below. I want to use host as 'accounts.google.com' (my actual path is 'https://accounts.google.com/o/oauth2/token') but the request is sent with path 'content.googleapis.com/o/oauth2/token'. The main problem is that gapi uses a relative url in the path parameter so even if i put the full path in 'path' it interpretes it starting with 'content.googleapis.com' followed by 'https://accounts.google.com/o/oauth2/token' which is obviously not even a valid url. So how do I set the path to be absolute rather than relative?
gapi.client.request({
'path':'/o/oauth2/token',
'method':'POST',
'params':{'rerfresh_token':refreshToken,'client_id':clientId,'client_secret':clientSecret,'grant_type':'refresh_token'}
});
request.execute();

Related

Laravel route is not letting me load my assets properly

In my laravel 9 project, when I have more than 4 '/' in my route, the project doesn't assets properly for that page. Because it includes the first keyword of my defined route.
For example: If I define a get route:
example.com/word1/word2/word3/word4/word5
In this case, all my other related routes such as my image links, where I've used route('/images/..')
The application loads the link: example.com/word1/images/... instead of example.com/images/...
I used '/' to solve this.
When you use a relative URL (e.g. /images/example.jpg), the browser will interpret it as being relative to the current page's URL. So if you're on a page with a URL like example.com/word1/word2/word3/word4/word5, then the relative URL /images/example.jpg will be interpreted as example.com/word1/word2/word3/word4/images/example.jpg.
To avoid this issue, you can use absolute URLs instead of relative URLs. An absolute URL includes the full URL, including the protocol (e.g. https://) and domain name. In your case, you can use the URL helper function to generate absolute URLs for your assets, like this: This will generate an absolute URL that includes only the domain name and the path to the asset, regardless of the current page's URL
<img src="{{ url('/images/example.jpg') }}" alt="Example">

Angular UI router href returned absolute URL lacks path

I'm using angular-ui-router, when browsing on my app, on URL
http://localhost:8080/referential/browse.action#/referential/collectivity/38470/181/services
I can call
$state.href(COLLECTIVITY_STATE, {collectivityId: collectivityId})
and I get
#/referential/collectivity/38470/181/services
That's fine but I want a full URL (ready to bookmark or send by email), according to the documentation, i add a parameter to href call:
$state.href(COLLECTIVITY_STATE, {collectivityId: collectivityId}, {absolute: true})
but what I get is
http://localhost:8080/#/referential/collectivity/38470/121/services
which is not the expected first URL: the path is lacking. How should I get the full URL?
You can use:
$location.absUrl();
to return the absolute URL (which includes the domain and protocol).
Be sure to include $location in your controller or factory dependency list.
app.factory("test", function($location)
{
console.log($location.absURL());
});

Relative URl crawling issue

I'm making a crawler that fetches all relative and absolute links. But if there is a relative url that is incorrect, then the crawler continues to prepare new absolute url in the website that handles incorrect urls with 200 response code.
Let's say, there is a relative link : "example/example.php", when I try to crawl http://example.com/example.com. When I find that page, I'll append and create a new link to crawl i.e. http://example.com/example/example.php. The problem is the page will again contain example/example.php which then appends to http://example.com/example/example/example.php.
Is there a better way of getting rid of this other than content comparison?

UriKind in windows phone navigation between pages

I am a windows phone developer. I use NavigationService class for navigating to different pages. In this we use a UriKind property. What is this property actually means ?..
I googled it but not get a clear answer about it.
In msdn they provide as
RelativeOrAbsolute : The kind of the Uri is indeterminate.
Absolute : The Uri is an absolute Uri.
Relative : The Uri is a relative Uri.
But I don't understand it yet.. Can anyone please help me ?
Basically Uri will will be used to fetch the information from the specified path. In that UriKind will decide whether the patch is Absolute or Relative.
Relative Uri : - This Uri will not be having the detailed information about the file path like.
/Images/Nature.png
Absolute Uri : - This Uri will give the detailed information about the file path from the foot itself.
D:/Projects/TestingApplication/Images/Nature.png
Relative Or Absolute : - This Uri might be Relative or Absolute that means Indeterminate

How to differentiate from the server side, between the first request of the browser (HTML file) and the following (images, CSS, scripts...)?

I'm programming a website with SEO friendly links, ie, put the page title or other descriptive text in the link, separated by slashes. For example: h*tp://www.domain.com/section/page-title-bla-bla-bla/.
I redirect the request to the main script with mod_rewrite, but links in script, img and link tags are not resolved correctly. For example: assuming you are visiting the above link, the tag request the file at the URL h*tp://www.domain.com/section/page-title-bla-bla-bla/js/file.js, but the file is actually http://www.domain.com/js/file.js
I do not want to use a variable or constant in all HTML file URLs.
I'm trying to redirect client requests to a directory or to another of the server. It is possible to distinguish the first request for a page, which comes after? It is possible to do with mod_rewrite for Apache, or PHP?
I hope I explained well:)
Thanks in advance.
Using rewrite rules to fix the problem of relative paths is unwise and has numberous downsides.
Firstly, it makes things more difficult to maintain because there are hundreds of different links in your system.
Secondly and more seriously, you destroy cacheability. A resource requested from here:
http://www.domain.com/section/page-title-bla-bla-bla/js/file.js
will be regarded as a different resource from
http://www.domain.com/section/some-other-page-title/js/file.js
and loaded two times, causing the number of requests to grow dozenfold.
What to do?
Fix the root cause of the problem instead: Use absolute paths
<script src="/js/file.js">
or a constant, or if all else fails the <base> tag.
This is an issue of resolving relative URIs. Judging by your description, it seems that you reference the other resources using relative URI paths: In /section/page-title-bla-bla-bla a URI reference like js/file.js or ./js/file.js would be resolved to /section/page-title-bla-bla-bla/js/file.js.
To always reference /js/file.js independet from the actual base URI path, use the absolute path /js/file.js. Another solution would be to set the base URI explicitly to / using the BASE element (but note that this will affect all relative URIs).

Resources