duanjia3187 2014-05-29 13:13
浏览 51
已采纳

在android中上传图片时出现IOException

Hi Iam trying to upload an image to server. But it is giving me IOException while uploading the image, which means the exception part is always get running. Pls help me how to resolve this problem.

Iam using the below code:

try {
                UpurlString = "http:/xxxxx/xxx/UpImage.php";
                length = fileInputStream.available();               
                //connectHTTP(UpurlString);
                url = new URL(UpurlString);
                conn = (HttpURLConnection) url.openConnection();                
                conn.setDoInput(true);
                conn.setDoOutput(true);
                conn.setUseCaches(false);
                conn.setRequestMethod("POST");
                conn.setRequestProperty("Connection", "Keep-Alive");
                conn.setRequestProperty("Content-Type",
                        "multipart/form-data;boundary=" + boundary);
                dos = new DataOutputStream(conn.getOutputStream());
                dos.writeBytes(twoHyphens + boundary + lineEnd);
                Log.e("FilenameCheck",filename);
                dos.writeBytes("Content-Disposition: form-data; name=\"userfile\";filename=\""
                        + filename + "" + lineEnd);
                dos.writeBytes(lineEnd);
                buffer = new byte[8192];
                bytesRead = 0;
                while ((bytesRead = fileInputStream.read(buffer)) > 0) {
                    dos.write(buffer, 0, bytesRead);
                    sentData += bytesRead;
                }
                dos.writeBytes(lineEnd);
                dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);               
                fileInputStream.close();
                dos.flush();
                dos.close();                        
                    inStream = new DataInputStream(conn.getInputStream());
                    while ((strResponse = inStream.readLine()) != null) {
                        Log.e("Response", strResponse);
                        /*if (strResponse.equalsIgnoreCase("The file " + filename
                                + " has been uploaded")) {                          
                        } else {                            
                        }*/
                    }
                    inStream.close();               
            } catch (IOException ioex) {
                Log.e("Debug", "error: " + ioex.getMessage(), ioex);
            }
  • 写回答

1条回答 默认 最新

  • doutouhe5343 2014-05-29 13:27
    关注

    There is a / in the url http:/webleads.usawebdept.com/IPhone/leadImage.php after http

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波