小智 5
这样做的方法是将其作为内容发送到 HttpPost 请求中,如下所示
HttpClient client = new DefaultHttpClient();
HttpPost postRequest = new HttpPost(url);
String body = getMessageBody();
try
{
postRequest.setEntity(new StringEntity(body, "UTF8"));
postRequest.setHeader("Content-Type", "application/x-www-form-urlencoded");
HttpResponse response = client.execute(postRequest);
return response;
} catch (UnsupportedEncodingException e)
{
e.printStackTrace();
} catch (ClientProtocolException e)
{
e.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
您对图像进行字符串编码的方式是执行以下操作。
BufferedImage img = ImageIO.read(new File("filename.jpg"));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(img, "jpg", baos);
baos.flush();
Base64 base = new Base64(false);
String encodedImage = base.encodeToString(baos.toByteArray());
baos.close();
encodedImage = java.net.URLEncoder.encode(encodedImage, "ISO-8859-1");
Run Code Online (Sandbox Code Playgroud)
祝你好运
Bor*_*jev -1
您不应该发送图像本身,而应该发送可以下载图像的 URL。
否则:
AndroidObject| 归档时间: |
|
| 查看次数: |
40428 次 |
| 最近记录: |