简体   繁体   English

更改URL的特定参数

[英]Change specific parameter of URL

I've node application and I'm getting the following URL (in req.header. of express) 我有node application ,正在获取以下URL(在express的req.header中)
I need to change the port number(of the redirect url ) eg from 77777 to 88888 , 我需要将( 重定向URL的 )端口号从77777更改为88888

I tried with parse encode and decode without success but maybe I miss something, 我尝试了解析编码和解码 ,但都没有成功,但也许我错过了一些东西,

I need to use the standard (parse encode and decode) way and not just replace ...(which works) 我需要使用标准的(解析编码和解码)方式, 而不仅仅是替换 ...(有效)

Any idea how to do that? 任何想法如何做到这一点? I need at the end after I change this URL to keep it in exactly the same format (After encod/decode...) as follows. 我需要在更改此URL后最后将其保持为完全相同的格式(在encod / decode ...之后),如下所示。

http://gr-t6fa45e73.go.grp.corp:54001/oauth/authorize?response_type=code&redirect_uri=http%3A%2F%2Fro-d3ma32e85.mo.grp.corp%3A77777%2Flogin%2Fcallback&client_id=zs6.node http://gr-t6fa45e73.go.grp.corp:54001 / oauth / authorize?response_type = code&redirect_uri = http%3A%2F%2Fro-d3ma32e85.mo.grp.corp%3A77777%2Flogin%2Fcallback&client_id = zs6.node

How about using url 如何使用网址

var URL ="http://gr-t6fa45e73.go.grp.corp:54001/oauth/authorize?response_type=code&redirect_uri=http%3A%2F%2Fro-d3ma32e85.mo.grp.corp%3A77777%2Flogin%2Fcallback&client_id=zs6.node";

var parts = URL.split("redirect_uri="),    
decoded = decodeURIComponent(parts[1])),
red = url.parse(decoded);
red.port=88888;
URL = parts[0]+"redirect_uri="+encodeURIComponent(url.format(red));

UPDATE Using this version of URI.js UPDATE使用此版本的URI.js

I use .build instead of .format. 我使用.build而不是.format。

DEMO 演示

Result: 结果:

http://gr-t6fa45e73.go.grp.corp:54001/oauth/authorize?response_type=code&redirect_uri=http%3A%2F%2Fro-d3ma32e85.mo.grp.corp%3A88888%2Flogin%2Fcallback%26client_id%3Dzs6.node http://gr-t6fa45e73.go.grp.corp:54001 / oauth / authorize?response_type = code&redirect_uri = http%3A%2F%2Fro-d3ma32e85.mo.grp.corp%3A88888%2Flogin%2Fcallback%26client_id%3Dzs6。节点

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM