이것은 내 코드입니다.안드로이드에서 multipart/form-data 업로드 그림/이미지 사용 방법
HTTP 400 오류가 발생했습니다. 누군가 나를 도울 수 있습니까?
HttpClient httpClient;
HttpPost httpPost;
HttpResponse response;
HttpContext localContext;
FileEntity tmp = null;
String ret = null;
httpClient = new DefaultHttpClient();
httpClient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.RFC_2109) ;
httpPost = new HttpPost(url);
tmp = new FileEntity(data,"UTF-8");
httpPost.setEntity(tmp);
httpPost.setHeader("Content-Type", "multipart/form-data");
httpPost.setHeader("access_token", facebook.getAccessToken());
httpPost.setHeader("source", data.getAbsolutePath());
httpPost.setHeader("message", "Caption for the photo");
localContext = new BasicHttpContext();
response = httpClient.execute(httpPost,localContext);
bobince, 이것은 나의 새로운 ID 덕분에, 내 연결 헤더에 OAuth를 넣어하려고합니다.
그리고 이것은 내 오래된 코드이므로 곧 업데이트 할 예정입니다.
private void uploadPicture() throws ParseException, IOException {
HttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
HttpPost httppost = new HttpPost("https://graph.facebook.com/me/photos");
File file = new File(sdpicturePath);
// DEBUG
Log.d("TSET", "FILE::" + file.exists()); // IT IS NOT NULL
Log.d("TEST", "AT:" + fbAccessToken); // I GOT SOME ACCESS TOKEN
MultipartEntity mpEntity = new MultipartEntity();
ContentBody cbFile = new FileBody(file, "image/png");
ContentBody cbMessage = new StringBody("TEST TSET");
ContentBody cbAccessToken = new StringBody(fbAccessToken);
mpEntity.addPart("access_token", cbAccessToken);
mpEntity.addPart("source", cbFile );
mpEntity.addPart("message", cbMessage );
httppost.setEntity(mpEntity);
// DEBUG
System.out.println("executing request " + httppost.getRequestLine());
HttpResponse response = httpclient.execute(httppost);
HttpEntity resEntity = response.getEntity();
// DEBUG
System.out.println(response.getStatusLine());
if (resEntity != null) {
System.out.println(EntityUtils.toString(resEntity));
} // end if
if (resEntity != null) {
resEntity.consumeContent();
} // end if
httpclient.getConnectionManager().shutdown();
} // end of uploadPicture()
일부 신체가 나를 돕습니다 .... – Joseph
안녕하세요, 어떻게이 문제를 해결 했습니까? 나는 지금 같은 문제에 직면하고있다. –