如何使用IO Codenameone发布图片/图像 [英] How do I post a picture/image using the IO Codenameone
问题描述
因为codenameone不能使用外部库(HttpConnection),所以我必须使用内部库/ API提供的Codenameone,这只是我设法通过使用ConnectionRequest将数据发布到格式化文本/字符串,我想知道有没有办法使用ConnectionRequest以图像的形式发布数据?感谢您的帮助
Because codenameone can not use external libraries (HttpConnection) then I have to use the internal library / API provided Codenameone, it's just that I've managed to post the data to format text / string by using ConnectionRequest, I want to know is there any way to post the data in the form of an image with using ConnectionRequest? Thank you for your help
Snippet ConnectionRequest我正在使用:
Snippet ConnectionRequest i'm using:
ConnectionRequest myrequest = new ConnectionRequest();
myrequest.setUrl("http://www.xxxx.com/mobile/login/");
myrequest.setPost(true);
myrequest.addArgument("email", "info@xxx.net");
myrequest.addArgument("password", "xxx");
myrequest.setPriority(ConnectionRequest.PRIORITY_CRITICAL);
NetworkManager.getInstance().addToQueue(myrequest);
myrequest.addResponseListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
NetworkEvent n = (NetworkEvent)evt;
// gets the data from the server as a byte array...
byte[] data = (byte[])n.getMetaData();
String response = new String(data);
}
});
推荐答案
当然可以添加图像数据作为参数对于请求,但您需要对其进行编码。或者,您可以覆盖该方法:
Sure you can just add the image data as an argument to the request but you will need to encode it. Alternatively you can override the method:
protected void buildRequestBody(OutputStream os) throws IOException
并在帖子输出流中写入您需要的任意数据。
And write into the post output stream any arbitrary data you need.
这篇关于如何使用IO Codenameone发布图片/图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!