웹서버는 VMplayer에 페도라를 설치해서 웹서버를 만들었구요
윈도우에서 VM에서구축한 웹서버 주소치고 들어가면 잘들어가집니다.
URL때문인지 conn.getoutputstream에서 문제인지 잘모르겠습니다.
(제일아래에소스첨부했습니다)
아래는 로그캣에 나온 오류입니다.
02-24 15:27:45.133: E/Upload file to server Exception(7388): Exception : failed to connect to /192.168.111.100 (port 80): connect failed: ETIMEDOUT (Connection timed out)
02-24 15:27:45.133: E/Upload file to server Exception(7388): java.net.ConnectException: failed to connect to /192.168.111.100 (port 80): connect failed: ETIMEDOUT (Connection timed out)
02-24 15:27:45.133: E/Upload file to server Exception(7388): at libcore.io.IoBridge.connect(IoBridge.java:114)
02-24 15:27:45.133: E/Upload file to server Exception(7388): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
02-24 15:27:45.133: E/Upload file to server Exception(7388): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:460)
02-24 15:27:45.133: E/Upload file to server Exception(7388): at java.net.Socket.connect(Socket.java:832)
02-24 15:27:45.133: E/Upload file to server Exception(7388): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:76)
02-24 15:27:45.133: E/Upload file to server Exception(7388): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
02-24 15:27:45.133: E/Upload file to server Exception(7388): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)
02-24 15:27:45.133: E/Upload file to server Exception(7388): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
02-24 15:27:45.133: E/Upload file to server Exception(7388): at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
02-24 15:27:45.133: E/Upload file to server Exception(7388): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:315)
02-24 15:27:45.133: E/Upload file to server Exception(7388): at libcore.net.http.HttpEngine.connect(HttpEngine.java:310)
02-24 15:27:45.133: E/Upload file to server Exception(7388): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:289)
02-24 15:27:45.133: E/Upload file to server Exception(7388): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:239)
02-24 15:27:45.133: E/Upload file to server Exception(7388): at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)
02-24 15:27:45.133: E/Upload file to server Exception(7388): at libcore.net.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:188)
02-24 15:27:45.133: E/Upload file to server Exception(7388): at com.example.filetest.MainActivity.uploadFile(MainActivity.java:114)
02-24 15:27:45.133: E/Upload file to server Exception(7388): at com.example.filetest.MainActivity$1$1.run(MainActivity.java:55)
02-24 15:27:45.133: E/Upload file to server Exception(7388): at java.lang.Thread.run(Thread.java:856)
02-24 15:27:45.133: E/Upload file to server Exception(7388): Caused by: libcore.io.ErrnoException: connect failed: ETIMEDOUT (Connection timed out)
02-24 15:27:45.133: E/Upload file to server Exception(7388): at libcore.io.Posix.connect(Native Method)
02-24 15:27:45.133: E/Upload file to server Exception(7388): at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:85)
02-24 15:27:45.133: E/Upload file to server Exception(7388): at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
02-24 15:27:45.133: E/Upload file to server Exception(7388): at libcore.io.IoBridge.connect(IoBridge.java:112)
02-24 15:27:45.133: E/Upload file to server Exception(7388): ... 17 more
final String uploadFilePath = "/mnt/sdcard/DCIM/Camera/";
final String uploadFileName = "1392025513112.jpg";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
uploadButton = (Button) findViewById(R.id.uploadButton);
messageText = (TextView) findViewById(R.id.messageText);
messageText.setText("Uploading file path :- " + uploadFilePath
+ uploadFileName + "'");
/************* Php script path ****************/
upLoadServerUri = "http://192.168.111.100:80/UploadToServer.php";
FileInputStream fileInputStream = new FileInputStream(
sourceFile);
URL url = new URL(upLoadServerUri);
// 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);
Log.e("QWE","dd");
Log.e("QWE","d"+conn.getOutputStream());
dos = new DataOutputStream(conn.getOutputStream());
Log.e("QWE","dd1");
dos.writeBytes(twoHyphens + boundary + lineEnd);
dos.writeBytes("Content-Disposition: form-data; name=\"uploaded_file\";filename=\""
+ fileName + "\"" + lineEnd);
Log.e("QWE","dd2");
dos.writeBytes(lineEnd);