서버에 파일을 업로드하는 안드로이드 응용 프로그램이 있습니다. 로컬 호스트에서는 아무런 문제없이 작동하지만 서버에서 작동하지 않으면 경로를 검사하여 올바른지 확인했습니다.서버에 안드로이드 업로드 파일이 404 오류가 발생합니다
로그 고양이 오류 : 찾을 수 없음이 : 내가 페이스트에 URL을 복사 할 경우 404
는 브라우저에서 내가 같은 주소에서 다른 PHP 파일 (up3.php)와 작업 하나가 작업
입니다 어떤 문제도없이 Json을 사용하여 파일을 보내지 않고 텍스트를 보내십시오.
내가 솔루션을 검색했지만 아무것도 찾지 못했습니다
이
내 코드입니다 :String upLoadServerUri = "http://live.mysite.com/up-file.php";
public int uploadFile(String sourceFileUri) {
String fileName = sourceFileUri;
HttpURLConnection conn = null;
DataOutputStream dos = null;
String lineEnd = "\r\n";
String twoHyphens = "--";
String boundary = "*****";
int bytesRead, bytesAvailable, bufferSize;
byte[] buffer;
int maxBufferSize = 1 * 1024 * 1024;
File sourceFile = new File(sourceFileUri);
if (!sourceFile.isFile()) {
dialog.dismiss();
runOnUiThread(new Runnable() {
public void run() {
}
});
return 0;
}
else
{
try {
// open a URL connection to the Servlet
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("Accept-Charset", "UTF-8");
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("ENCTYPE", "multipart/form-data");
conn.setRequestProperty("Content-Type", "multipart/form-data ; charset=utf-8 ;boundary=" + boundary);
conn.setRequestProperty("uploaded_file", fileName);
dos = new DataOutputStream(conn.getOutputStream());
dos.writeBytes(twoHyphens + boundary + lineEnd);
dos.writeBytes("Content-Disposition: form-data; name=\"post_id\""+ lineEnd);
dos.writeBytes(lineEnd);
dos.writeBytes(post_id);
dos.writeBytes(lineEnd);
dos.writeBytes(twoHyphens + boundary + lineEnd);
dos.writeBytes("Content-Disposition: form-data; name=\"username\""+ lineEnd);
dos.writeBytes(lineEnd);
dos.writeBytes(username);
dos.writeBytes(lineEnd);
dos.writeBytes(twoHyphens + boundary + lineEnd);
dos.writeBytes("Content-Disposition: form-data ; name=\"txt\""+ lineEnd);
dos.writeBytes(lineEnd);
dos.writeUTF(up_txt);
dos.writeBytes(lineEnd);
dos.writeBytes(twoHyphens + boundary + lineEnd);
dos.writeBytes("Content-Disposition: form-data; name=\"uploaded_file\";filename=\""
+ fileName + "\"" + lineEnd);
dos.writeBytes(lineEnd);
// create a buffer of maximum size
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
buffer = new byte[bufferSize];
// read file and write it into form...
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
while (bytesRead > 0) {
dos.write(buffer, 0, bufferSize);
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
}
// send multipart form data necesssary after file data...
dos.writeBytes(lineEnd);
dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
// Responses from the server (code and message)
serverResponseCode = conn.getResponseCode();
String serverResponseMessage = conn.getResponseMessage();
Log.i("uploadFile", "HTTP Response is : "
+ serverResponseMessage + ": " + serverResponseCode);
if(serverResponseCode == 200){
runOnUiThread(new Runnable() {
public void run() {
}
});
}
//close the streams //
fileInputStream.close();
dos.flush();
dos.close();
} catch (MalformedURLException ex) {
dialog.dismiss();
ex.printStackTrace();
runOnUiThread(new Runnable() {
public void run() {
}
});
Log.e("Upload file to server", "error: " + ex.getMessage(), ex);
} catch (Exception e) {
dialog.dismiss();
e.printStackTrace();
runOnUiThread(new Runnable() {
public void run() {
}
});
Log.e("Upload file to server Exception", "Exception : "
+ e.getMessage(), e);
}
dialog.dismiss();
return serverResponseCode;
} // End else block
로그인 고양이 :
10-16 06:08:53.632: W/IInputConnectionWrapper(2571): showStatusIcon on inactive InputConnection
10-16 06:08:58.541: D/dalvikvm(2571): GC_CONCURRENT freed 169K, 3% free 9758K/10055K, paused 15ms+1ms, total 18ms
10-16 06:08:58.551: D/dalvikvm(2571): GC_FOR_ALLOC freed 608K, 10% free 9150K/10055K, paused 2ms, total 2ms
10-16 06:08:58.551: I/dalvikvm-heap(2571): Grow heap (frag case) to 10.340MB for 1440012-byte allocation
10-16 06:08:58.571: D/dalvikvm(2571): GC_CONCURRENT freed 0K, 8% free 10557K/11463K, paused 12ms+1ms, total 15ms
10-16 06:09:03.742: I/Choreographer(2571): Skipped 30 frames! The application may be doing too much work on its main thread.
10-16 06:09:11.862: I/uploadFile(2571): HTTP Response is : Not Found: 404
귀하의 DNS를 수정하십시오 ... – 323go
브라우저 하위 도메인에서 아무 문제없이 작동합니다 –