Android 용 프로그램을 작성하여 HTTP POST로 서버에 파일을 업로드했습니다.POST로 Android에 파일을 업로드하는 중 오류가 발생했습니다.
이전에는 문제가 없었지만 지금은 작동하지 않는 이유를 알지 못합니다. Android 기기로 테스트 중입니다. 난 그냥 에뮬레이터와 잘 작동하는지 확인했습니다.
브라우저에서 해당 링크를 열면 여전히 제대로 작동하고 올바르게 열립니다.
어떤 신체가 문제가 될 수 있는지 알려주시겠습니까 ???
나는이 오류가 발생하지 오전 : (호스트 이름과 연관된 주소) 여기
10-07 04:28:14.410: I/System.out(1280): executing request POST http:////path/to/my/server//api/index.php/match HTTP/1.1
10-07 04:28:14.450: W/System.err(1280): java.net.UnknownHostException: Unable to resolve host "//path/to/my/server/": No address associated with hostname
내 코드입니다 ...
private class UploadFilesTask extends AsyncTask<File, Void, Void> {
@Override
protected Void doInBackground(File... arg0) {
HttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
enter code here
// I have not shown my REAL server address due so some restriction, So assume below URL is correct
HttpPost httppost = new HttpPost("http://path/to/my/server/"); //Assume path is correct
//File file = new File("/mnt/sdcard/DCIM/Camera/01.jpg");
MultipartEntity mpEntity = new MultipartEntity();
ContentBody cbFile = new FileBody(arg0[0], "image/jpeg");
mpEntity.addPart("userfile", cbFile);
httppost.setEntity(mpEntity);
System.out.println("executing request " + httppost.getRequestLine());
HttpResponse response = null;
try {
response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
HttpEntity resEntity = response.getEntity();
System.out.println(response.getStatusLine());
if (resEntity != null) {
try {
//audioFilename = EntityUtils.toString(resEntity);
System.out.println(EntityUtils.toString(resEntity));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (resEntity != null) {
try {
resEntity.consumeContent();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
httpclient.getConnectionManager().shutdown();
return null;
}
}
답장을 보내 주셔서 감사합니다. 완료. – Vishal
원인은 무엇입니까? 당신이 그것을 공유 할 수 있다면 좋을 것이고, 다른 사람들도 똑같은 문제를 겪었다면 그것을 해결할 수있을 것입니다. – Infinity