duanjia3187
2014-05-29 13:13
浏览 50

在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

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题