HTTP POST Web请求的哪些部分需要进行URL编码?(What parts of a HTTP POST web request need to be URL Encoded?)
我一直在寻找答案,但我对POST数据的哪些部分需要进行URL编码感到困惑。 我正在提交带有名称/值参数的HTTP发布请求,以及content-type:application / x-www-form-urlencoded。
我是否需要构建我的整个参数字符串ie)encode(postData)或者然后分别编码每个名称/值对? encode(paramName)+“=”+ encode(paramValue)+“&”
从Chrome开发人员工具我尝试复制的原始请求看起来像选项2,但我在网上看到的似乎表明选项1。
谢谢
I have been browsing for an answer, but I am a bit confused about which parts of POST data need to be URL encoded. I am submitting an HTTP post request with name/value parameters, and content-type: application/x-www-form-urlencoded.
Do I need to build my entire parameter string ie) encode(postData) or and then encode each name/value pair separately? encode(paramName) + "=" + encode(paramValue) + "&"
From Chrome developer tools the raw request I'm trying to replicate looks like option 2, but what I've read online seems to indicate option 1.
Thanks
原文:https://stackoverflow.com/questions/26848523
最满意答案
如果我理解了这个问题,你可以给你的输入命名,然后做
setState({[e.target.name]: e.target.value})
。If I understand the question, you could give your inputs a name and then do
setState({[e.target.name]: e.target.value})
.
相关问答
更多-
TCP/IP模型是一个________。[2023-10-02]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
通过道具时不要使用绑定 那么你可以这样做 onPress={this.handleSubmit} handleSubmit = () => {...} Don't Use Bind When Passing Props then you can do like this onPress={this.handleSubmit} handleSubmit = () => {...}
-
class App extends React.Component { constructor(props) { super(props); this.state = { users: [ { firstName: 'John1', middleName: 'Daniel1', lastName: 'Paul1' }, { firstName: 'John2', middleName: 'Daniel2', lastName: 'P ...
-
使用单个处理函数在React中设置表单中的输入状态(Using a single handler function to set the state of inputs in a form in React)[2022-06-03]
如果我理解了这个问题,你可以给你的输入命名,然后做setState({[e.target.name]: e.target.value}) 。 If I understand the question, you could give your inputs a name and then do setState({[e.target.name]: e.target.value}). -
如果你想确保你在handleSubmit有一个当前的输入值,可以使用传入的SyntheticEvent来访问表单中的输入 。 lass NameForm extends React.Component { constructor(props) { super(props); this.state = {value: ''}; this.handleChange = this.handleChange.bind(this); this.handleSubmit = thi ...
-
constructor(props) { super(props); this.state = { textValue: '', emailValue: '' } } handleTextChange(e) { this.setState({ textValue: e.target.value }) } handleEmailChange(e) { this.setState({ emailValue: e.target.value }) } ...
-
因为您希望两个组件根据选择呈现数据,所以应该让应用程序执行状态管理并将数据作为props传递给每个组件。 var App = React.createClass({ getInitialState: function() { return {value: 'cat'}; }, handleChange: function(e) { e.preventDefault(); this.setState({value: e.target.va ...
-
何时设置React状态?(Notifying when React state is set?)[2020-12-08]
你试过这个吗? this.setState({ state : newState }, () => { // Call some method when state changes were done. }); 你也应该使用e.preventDefault(); 因为您没有将for提交给任何服务器。 handleClick(e) { e.preventDefault(); const xhttp = new XMLHttpReq ... -
你已经花了很多时间思考这个并查找相关的讨论。 对于它的价值,我认为你实际上是在过度思考这个问题。 React的核心是一个非常实用的工具。 它会向您推动某些方向,并且肯定会被认为是惯用的方法,但它提供了许多逃脱舱口,允许您打破基本方法以适合您的特定用例。 因此,如果您需要以一种特定的方式构建事物以使您的应用程序按照您希望的方式运行,请不要花时间担心它是否“绝对完全符合React的原则”。 偏离某些神话般的理想,没有人会对你大喊大叫:) 是的,您提供的示例代码乍一看似乎非常合理。 You've clearly ...