1
curl -F [email protected]/path/to/index.html -u [email protected] -F 'data={"title":"API V1 App","package":"com.alunny.apiv1","version":"0.1.0","create_method":"file"}' https://build.phonegap.com/api/v1/apps
나는 HttpClient 라이브러리를 사용하여 자바 프로그램을 사용하여 동일한 것을 달성하려고 노력하고있다. 위의 코드 난 단지 StringEntity 또는 FileEntity을 설정할 수 있지만 둘 다 내가이 컬 명령의 기능을 얻기 위해 필요한 것을 생각 할 수 있습니다에서cURL 명령을 사용하여 자바
DefaultHttpClient client = new DefaultHttpClient();
HttpHost targetHost = new HttpHost("build.phonegap.com", 443, "https");
client.getCredentialsProvider().setCredentials(
new AuthScope(targetHost.getHostName(), targetHost.getPort(),AuthScope.ANY_REALM),
new UsernamePasswordCredentials("[email protected]", "abc123"));
String authToken = "?auth_token=abcdefgh";
HttpPost httpPost = new HttpPost("https://build.phonegap.com/api/v1/apps" + authToken);
String jsonString = "{\"title\":\"API V1 App\",\"create_method\":\"file\"}";
MultipartEntity multipartEntity = new MultipartEntity();
multipartEntity.addPart(new FormBodyPart("data", new StringBody(jsonString)));
multipartEntity.addPart("file", new FileBody(new File("C:/Users/Desktop/app.zip")));
/*StringEntity entity = new StringEntity(jsonString, "UTF-8"); */
httpPost.setEntity(multipartEntity);
System.out.println("executing request " + httpPost.getRequestLine());
HttpResponse httpResponse = client.execute(httpPost);
HttpEntity entity = httpResponse.getEntity();
System.out.println(httpResponse.getStatusLine());
if(entity != null){
System.out.println(EntityUtils.toString(entity));
}
.
는 StringEntity 및 FileEntity으로 시도 후 나는 가 사전에 ..감사합니다 자세한 내용은 저를 제공하시기 바랍니다 및 예, 가능하면 수 ... MultipartEntity하지만 운했습니다.
MultipartEntity multipartEntity = new MultipartEntity(
HttpMultipartMode.BROWSER_COMPATIBLE
) ;
이것은 나를 위해 일한 :