过程是什么?对于 C#,我正在尝试通过 HTTP 客户端获取图像并发送,也许,在服务器上只得到一个空白图像,这是 Xamarin 表单上的代码:
<forms:SignaturePadView
BackgroundColor="Transparent"
StrokeColor="Blue"
StrokeWidth="3"
HeightRequest="250"
Name="Signature"
/>
在视图模型中:
Stream image = await Signature.GetImageStreamAsync(SignatureImageFormat.Png);
发送:
var bytes = new byte[image.Length];
await image.ReadAsync(bytes, 0, (int)image.Length);
string imageBase64 = Convert.ToBase64String(bytes);
根据要求:
try
{
var client = new HttpClient();
var response = await client.PostAsync(urlBase,
new StringContent(string.Format(
"imgSign={0}",
imageBase64),
Encoding.UTF8, "application/x-www-form-urlencoded"));
if (!response.IsSuccessStatusCode)
{
return response.ToString();
}
else
{
var response = await response.Content.ReadAsStringAsync();
return response;
}
}
catch
{
return null;
}
服务器通过发布请求接收并使用 file_puts_contents 将图像发送到文件夹:
if (isset ($image = $_POST['imgSign'])) {
$dateNow = date("d-m-Y");
$imageName = 'Id'.$dateNow;
$image = $_POST['imgSign'];
$path = "../images/$imageName.png";
if(file_put_contents($path,base64_decode($image))){
...update DB
}
}