2013-01-08 250 views
-1
<html> 
<head><title></title></head> 
<body> 
<form action="https://oauth.vk.com/authorize?client_id=3343995&scope=photos,wall,offline&redirect_uri=http://example.com/vkontakte/auth&response_type=code" method="get"> 
<input type="submit" value="Auth"> 
</form> 
</body> 
</html> 

你好。我遇到了这个HTML的问题。当我点击提交按钮时,我希望转到https://oauth.vk.com/authorize?client_id=3343995&scope=photos,wall,offline&redirect_uri=http://example.com/vkontakte/auth&response_type=code链接,但是我转到https://oauth.vk.com/authorize没有重定向。当我提交表单时,为什么这个URL会出错?

+1

如果使用'action =“POST”',它会工作吗?用'action =“GET”',我认为动作URI中的查询字符串被替换为表单字段。 – Barmar

+0

@Barmar我认为你是对的,如果你看看我的答案,将查询参数置于隐藏字段中正确地将它们传递到URL中(并正确地对其进行URL编码)。我正在窃取你的想法并将其放入我的答案:) –

回答

1

当您的表单使用method="get"时,查询参数将从action属性中删除,表单元素将在URL的查询字符串中进行URL编码。

如果您可以使用POST,您可以将表格更改为使用method="POST",它将起作用。你还是应该正确编码的URL名称和值http://jsfiddle.net/9FmtW/3/

如果你必须使用一个GET,你必须包括在您的形式http://jsfiddle.net/9FmtW/这是你的查询参数隐藏字段具有正确的URL编码的查询字符串参数的利益

<form action="https://oauth.vk.com/authorize" method="get"> 
    <input type="hidden" name="client_id" value="3343995" /> 
    <input type="hidden" name="scope" value="photos,wall,offline" /> 
    <input type="hidden" name="redirect_uri" value="http://example.com/vkontakte/auth" /> 
    <input type="hidden" name="response_type" value="code" /> 
    <input type="submit" value="Auth" /> 
</form> 

enter image description here

您的网址包含在它的URL,你需要转义特殊URL特定的字符,如&=

+0

看起来我需要逃避“?”,你能告诉我这个逃生角色吗? – user1956592

+0

他的例子已经逃脱了问号。如果仔细观察,可以在'auth'和'response'之间看到'%26'。不要试图逃避这些;使用编码器。 –

+0

您不需要转义URL中的第一个问号,而只需转移内部URL中的问号。无论如何,你总是可以使用'encodeURIComponent(“?”)'来确定转义值是什么。嗯......你的内部网址没有'?'? –

相关问题