小编Nag*_*yan的帖子

需要将图像和文本发送到服务器

在我的应用程序中,我需要将图像和笔记(180个文本)发送到服务器.

现在能够单独发送图像和文本,但我现在需要一起发送.

方法是什么?

目前我正在使用线程发送图像.

// open a URL connection to the Servlet
                FileInputStream fileInputStream = new FileInputStream(
                        sourceFile);
                URL url = new URL(
                        "http://xxx.com/image.php");

                // Open a HTTP connection to the URL
                conn = (HttpURLConnection) url.openConnection();
                conn.setDoInput(true); // Allow Inputs
                conn.setDoOutput(true); // Allow Outputs
                conn.setUseCaches(false); // Don't use a Cached Copy
                conn.setRequestMethod("POST");
                conn.setRequestProperty("Connection", "Keep-Alive");
                conn.setRequestProperty("ENCTYPE", "multipart/form-data");
                conn.setRequestProperty("Content-Type",
                        "multipart/form-data;boundary=" + boundary);
                conn.setRequestProperty("uploaded_file", fileName);
                // conn.setRequestProperty("id", imei);

                dos = new DataOutputStream(conn.getOutputStream());

                dos.writeBytes(twoHyphens + boundary + lineEnd);
                dos.writeBytes("Content-Disposition: form-data; name=uploaded_file; filename="
                        + fileName …
Run Code Online (Sandbox Code Playgroud)

php android http

2
推荐指数
1
解决办法
2401
查看次数

标签 统计

android ×1

http ×1

php ×1