Win a copy of Spark in Action this week in the Open Source Projects forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

How can intercept one HTTP request and modify the URL parameter?

 
Ranch Hand
Posts: 459
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I want to intercept one http request (get) and modify one parameter send by url parameter.

I read that there are the interface httpintercept but I don't know how can modify the parameter send by url parameter.

So, URL : http://site/api/rest?k=yyyyyyyyy.

I wanted to send http://site/api/rest?k=vvvvvvvv.

Can someone help me?

Thanks in advance
 
Sheriff
Posts: 21971
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this on the client or on the server? And what libraries / frameworks are you using? For instance, does this need to be done in a servlet environment, or when using URLConnection, or when Apache's HttpClient, etc...
 
Dana Ucaed
Ranch Hand
Posts: 459
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is about a call on client and you can user JS or TypeScript,

 
Dana Ucaed
Ranch Hand
Posts: 459
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use URLConnection or Apache HTTP.
 
Marshal
Posts: 3141
465
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dana Ucaed wrote:I read that there are the interface httpintercept but I don't know how can modify the parameter send by url parameter.


You are talking about Angular HttpInterceptor interface - right?
 
Dana Ucaed
Ranch Hand
Posts: 459
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep.

 
Ranch Hand
Posts: 97
AngularJS Chrome Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We cannot directly modify the request URL in intercept method, Since url is const in HttpRequest

We need to close the request object and modify URL something like below.

 
Saloon Keeper
Posts: 6506
158
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dana Ucaed wrote:You can use URLConnection or Apache HTTP.


These are Java classes/libraries - that contradicts your assertion that it is about Angular (or "JS or TypeScript") - please clarify.
 
Dana Ucaed
Ranch Hand
Posts: 459
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need for Java and / or TypeScript.

 
Dana Ucaed
Ranch Hand
Posts: 459
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to add some clarifications.

When in a app I did the request : https://numesite.com?key=llllll and want to modify the value of key.

Thanks.

 
Dinesh Kumar Ramakrishnan
Ranch Hand
Posts: 97
AngularJS Chrome Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use regex match or string replace to do this in the interceptor

Dinesh Kumar Ramakrishnan wrote:We cannot directly modify the request URL in intercept method, Since url is const in HttpRequest

We need to close the request object and modify URL something like below.

 
Dana Ucaed
Ranch Hand
Posts: 459
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I appreciate your response.

 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic