cUrl에서 Android로 이동하는 데는 몇 가지 질문이 있지만 찾은 파일 업로드는 다루지 않습니다.파일과 함께 CUrl을 Android HttpUrlConnection으로 변환하십시오.
이 컬 요청 작동 : 내가 노력하고
$ curl -X PUT -u user:password --data-binary @myfile.pdf "https://example.com/myurl?id=myid&filename=myfile.pdf&title=My+Title&mimetype=application/pdf"
:
String url = "https://example.com/myurl?id=myid&filename=myfile.pdf&title=My+Title&mimetype=application/pdf";
String fileUrl = "myfile.pdf";
String userPassword = "user:password";
String userpass = Base64.encodeToString(userPassword.getBytes(), Base64.DEFAULT);
File f = new File(fileUrl);
if(f.isFile()) {
HttpURLConnection c = null;
URL u = null;
try {
u = new URL(url);
c = (HttpURLConnection) u.openConnection();
c.setRequestProperty("Authorization", "Basic " + userpass);
c.setDoOutput(true);
c.setRequestMethod("PUT");
c.setRequestProperty("Content-Type", "multipart/form-data");
FileInputStream fis = new FileInputStream(f);
long fl = f.length();
output(fis, c.getOutputStream(), fl);
} catch (Exception e) {
e.printStackTrace();
}
output(fis, c.getOutputStream(), fl);
가 inputStream을이 OutputStream에 기록
다음/모두를 플러시 닫습니다.
나는 method not allowed
의 응답을 받고 있는데, 누구나 내가 뭘 잘못하고 있는지 알아?
편집 : 그것은 (나에게) 정말 이상한 그들의 응답 헤더를 가지고 : Allow: POST,OPTIONS,GET,HEAD
하지만 PUT
컬 작품을 사용.
편집 두 :
이컬을 사용하는 경우 실제로 얻을 :
Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE
을하지만 컬 사용자 에이전트 사용자 에이전트를 설정 한 경우에도, HttpURLConnection의를 사용하는 경우, 더 Access-Control-Allow-Methods
없다 c.getHeaderField()
을 사용하십시오. 대신 필드는 단순히 Allow
이며 PUT이 없습니다.