console.log(Qs.stringify({id: link, key: secretKey}))输入结果格式;url编码后的
import Qs from 'qs'
// 。。。
confirm = e => { let secretKey = this.contentSecretKeyInput.state.value secretKey = AESUtils.encryption(secretKey, config.frontSecretKey) let { link } = this.state link = link.substring(link.lastIndexOf('/') + 1) console.log(Qs.stringify({id: link, key: secretKey})) Axios.get('/api/encryption?' + Qs.stringify({id: link, key: secretKey})).then(res => { if (res.data.code === 0) { let content = res.data.data.content this.setState({ content }) // destroy dialog this.state.modal.destroy(); //message.success('Successful'); ReactDOM.render( <div> <span className='content-info'>The content you extract is:</span> <TextArea rows={8} value={this.state.content} /> <Button className='copy-button' type="primary" onClick={this.buttonCopyHandler}>Copy</Button> </div>, document.getElementById('guestdecrypt-container'), ); } else { // error message info if (res.data.data && res.data.data.incr) message.error(`${res.data.message}, only ${res.data.data.incr} input opportunities left`); else message.error(res.data.message); } }) }
---
buttonClickHandler = () => { let { content, pwd } = this.state content = AESUtils.encryption(content, config.frontSecretKey) pwd = AESUtils.encryption(pwd, config.frontSecretKey) const status = 0 // 0: normal const obj = { content, pwd, status } console.log(Qs.stringify(obj)) Axios.post('/api/encryption', Qs.stringify(obj), { headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }).then(res => { //console.log(res) //console.log("res.data.code=" + res.data.code) if (res.data.code === 0) { // console.log(res.data.data) //message.success('Successful'); const postResult = res.data.data const url = config.baseLink + postResult.id this.setState({ postResult, url }) const modal = Modal.confirm({ title: 'Resource Link', icon: <Icon type="info-circle" />, // content: <Input placeholder="Please Input the Secret Key" ref={input => this.contentSecretKeyInput = input} />, content: ( <div> <span className='encry-link-tip'>Resources are only saved for 5 minutes.</span> <Input value={this.state.url} ref={input => this.urlInput = input} /> </div> ), okText: 'Copy', cancelText: 'Close', onOk: e => this.copyToClipboard(e) }) this.setState({modal}) } else { message.error(res.data.message); } }) }
---