2016-06-23 3 views
0

에서 작동하지 않습니다. 그것은 로컬 호스트 및 Bluehost를 에 아주 잘 작동합니다. 하지만 (Go Daddy)와 같은 호스팅에서는 작동하지 않습니다. 아무도 왜 설명하겠습니까 ???안드로이드 HTTP 클라이언트 업로드 내가 서버에 파일을 업로드하려면 다음 코드를 사용하고 일부 서버

data = IOUtils.toByteArray(inputStream); 
    HttpClient httpClient = new DefaultHttpClient(); 
    HttpPost httpPost = new HttpPost(upload_url); 
    InputStreamBody inputStreamBody = new InputStreamBody(new ByteArrayInputStream(data), fileName); 
    CustomMultiPartEntity multipartEntity = new CustomMultiPartEntity(); 
    multipartEntity.setUploadProgressListener(this); 
    multipartEntity.addPart("pdf", inputStreamBody); 
    multipartEntity.addPart("title", new StringBody(title)); 
    multipartEntity.addPart("subject", new StringBody(subject)); 
    multipartEntity.addPart("college", new StringBody(college)); 
    multipartEntity.addPart("stream", new StringBody(stream)); 
    multipartEntity.addPart("branch", new StringBody(branch)); 
    multipartEntity.addPart("userID", new StringBody(String.valueOf(userid))); 
    httpPost.setEntity(multipartEntity); 
    HttpResponse httpResponse = httpClient.execute(httpPost); 

많은 테스트를 수행했습니다. 서버에서 $_POST[]을 통해 값을 검색하면 값은 null입니다. HttpUrlConnection은 모든 서버에서 작동합니다. 그러나 우리는 모든 것을 스스로 써야합니다. 나는 왜 업로드와 같은 간단한 함수를 위해 처음부터 너무 많은 코드를 작성해야 하는지를 의미한다. 간단한 콜백을 가진 라이브러리가 없다.

+0

이 될 수 있습니다! 그래서 당신은 HttpURLConnection을 사용하려고 시도해야합니다 –

+0

HttpURLConnection은 작동하지만 우리는 많은 쓰레기를 써야합니다. 만약 내가 하나를 사용하고 잘 작동하면 도서관을 제안해라. –

+0

다중 접속은 또한 추천하지 않는다. ... httpurlconnection은 최선의 접근이다. –

답변

0

HttpClient를, HttpPost ..는 API 22에 사용되지 않습니다, 그래서 당신은 대신 HttpURLConnection의 사용하려고합니다. 지금은 사용되지 않습니다 HttpClient를 때문에

+0

나는 처음부터 다시 쓰고 싶지 않다 ... 나는 httpurlconnection에 많은 쓰레기를 써야만한다는 것을 의미한다. 당신이 하나를 사용하면 몇 가지 도서관 제안 ... –

+0

당신은 안드로이드에서 네트워킹을 관리하는 다양한 옵션이 있습니다. http://stackoverflow.com/questions/6341400/alternative-http-client-library-for-android : 대안 라이브러리이 문서를 따라 – alway5dotcom