如何将具有多个参数的URL传递到URL中? [英] How do I pass a URL with multiple parameters into a URL?

查看:96
本文介绍了如何将具有多个参数的URL传递到URL中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我试图通过这样一个URL:

  www.foobar.com/?first=1& second = 12& third = 5 

放入这样的网址:

  http://www.facebook.com/sharer.php?&t=FOOBAR&u=http://www.foobar.com/first= 12& amp; sec = 25& amp; amp; position = 2 

它只识别第一个参数。我在LinkedIn和Twitter分享中遇到了同样的问题,所以它一定是我做错了。

html编码你的URL参数,你需要 URL编码它:

  http://www.facebook.com/sharer.php?&t=FOOBAR&u=http%3A%2F%2Fwww.foobar.com%2F% 3Ffirst%3D12%26sec%3D25%26position%3D 

在大多数语言中,在JavaScript中的一个href =https://stackoverflow.com/questions/332872/how-to-encode-a-url-in-javascript:

  var encodedParam = encodeURIComponent('www.foobar.com/?first=1&second=12&third=5'); 
// encodedParam ='http%3A%2F%2Fwww.foobar.com%2F%3Ffirst%3D12%26sec%3D25%26position%3D'

(其他语言也有相同的方法)


Basically I'm trying to pass a URL like this:

www.foobar.com/?first=1&second=12&third=5

into a URL like this:

http://www.facebook.com/sharer.php?&t=FOOBAR&u=http://www.foobar.com/first=12&sec=25&position=2

It only recognizes the first parameter. I'm having the same problem with LinkedIn and Twitter sharing, so it must be something I'm doing wrong.

解决方案

Rather than html encoding your URL parameter, you need to URL encode it:

http://www.facebook.com/sharer.php?&t=FOOBAR&u=http%3A%2F%2Fwww.foobar.com%2F%3Ffirst%3D12%26sec%3D25%26position%3D

You can do this easily in most languages - in javascript:

var encodedParam = encodeURIComponent('www.foobar.com/?first=1&second=12&third=5');
// encodedParam = 'http%3A%2F%2Fwww.foobar.com%2F%3Ffirst%3D12%26sec%3D25%26position%3D'

(there are equivalent methods in other languages too)

这篇关于如何将具有多个参数的URL传递到URL中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆