android - 当用户在反应原生 android 设备中输入印度卢比符号 (₹) 或其他货币符号时,他们将作为“₹”发送到服务器
问题描述
当用户在 android 输入字段中键入像印度卢比 ₹ 之类的货币符号并单击提交时,发送到服务器的值是“¹”而不是请求中的 ₹。
但是,当我在发出 axios api 请求之前打印控制台时,它会在控制台中正确打印 ₹。
所以我认为在发出 axios 请求时可能需要进行一些编码。
如果有人知道如何在本机反应中发送特殊符号,请帮助我。
我使用 fetch 的示例代码
let data = {
message: this.state.internalValue,
};
fetch('https://www.myapi.com', {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
body:JSON.stringify(data)
});
使用 axios
axios.post("https://www.myapi.com", data)
.then(response => {
})
.catch(error => {
});
在 axios 中使用表单数据
let jsondata = {
message: this.state.internalValue,
};
var axios = require('axios');
var FormData = require('form-data');
var data = new FormData();
data.append('data', true);
var config = {
headers: {
'Content-Type': 'application/json; charset=utf-8',
},
};
axios.post('https://myapi.com',jsondata,config)
.then((response) => {
})
.catch(error => {
});
当前行为
当我在 android studio profiler 中调试请求时,值是这样发送的,而不是 ₹。
{
"message": "₹"
}
解决方案
尝试像
For formdata
const formData = new FormData();
formData.append("data", true);
const config = {
headers: {
"Content-Type": "multipart/form-data; charset=utf-8;"
}
};
axios.post(URL, formData, config).then(
response => {
console.log({ response });
},
error => {
console.log({ error });
}
);
For normal fetch
fetch(uri, {
headers:{
contentType: "application/json; charset=utf-8",
}
})
.then(
(response) => {
var contentType = response.headers.get('content-type')
console.warn(contentType)
return response.json()
}
).then((myJson) => {
console.log(JSON.stringify(myJson));
}).catch((err) => {
console.log(err)
})
}
推荐阅读
- openssl - Crystal lang on Apple Silicone M1
- c# - Autogenerate OpenAPI documentation with Azure Functions
- javascript - can't target div inside a mailchimp form
- docker - ssh and docker: the input device is not a TTY
- php - PHPExcel styling sheets using fromArray() function
- python - Using python mysql pooling with docker container to get close pooled connections
- authentication - Cypress automatically deletes token from browser?
- android - Retrofit Error Handling with different types of responses
- sql - Grouping is very slow on PostgreSQL even with index
- reactjs - How to pass data from one React website to another React Website