复代码代码如下:
private static String url = PropertiesLoader.getProperty("ALLYES_SERVER", false);
개인 정적 문자열 사용자 이름 = PropertiesLoader.getProperty("ALLYES_USERNAME", false);
개인 정적 문자열 비밀번호 = PropertiesLoader.getProperty("ALLYES_PASSWORD", false);
/**
* 添加创의미
*
* @param creativeAudit
* @반품
*/
공개 정적 Map<String, Object> addCreative(CreativeAudit creativeAudit) {
//이름,너비,높이,유형,creativeTagId, 코드,bindId
문자열 유형 = "9";
if (creativeAudit.getRelative_path().toLowerCase().endsWith("gif"))
유형 = "10";
if (creativeAudit.getRelative_path().toLowerCase().endsWith("swf"))
유형 = "11";
Map<String, Object> 결과 = new HashMap<String, Object>();
문자열 addUrl = url + "/creatives/add";
DefaultHttpClient httpClient = new DefaultHttpClient();
httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(사용자 이름, 비밀번호));
노력하다 {
List<NameValuePair> postparams = new ArrayList<NameValuePair>();
postparams.add(new BasicNameValuePair("name", creativeAudit.getName()));
postparams.add(new BasicNameValuePair("width", Integer.toString(creativeAudit.getWidth())));
postparams.add(new BasicNameValuePair("height", Integer.toString(creativeAudit.getHeight())));
postparams.add(new BasicNameValuePair("type", type));
postparams.add(new BasicNameValuePair("creativeTagId", creativeAudit.getAdCategory().getAd_caterory().substring(2)));
postparams.add(new BasicNameValuePair("code", creativeAudit.getCode()));
postparams.add(new BasicNameValuePair("bindId", creativeAudit.getGeoid()));
UrlEncodedFormEntity 엔터티 = new UrlEncodedFormEntity(postparams, "UTF-8");
HttpPost httpPost = new HttpPost(addUrl);
httpPost.setEntity(entity);
HttpResponse httpResponse = httpClient.execute(httpPost);
int statusCode = httpResponse.getStatusLine().getStatusCode();
if (statusCode == HttpStatus.SC_OK) {
HttpEntity httpEntity = httpResponse.getEntity();
String createResult = EntityUtils.toString(httpEntity, "UTF-8");
JSONObject jsonObject = JSONObject.fromObject(createResult);
String uuid = jsonObject.get("id").toString();
creativeAudit.setUuid(uuid);
result.put("성공", creativeAudit);
} 또 다른 {
HttpEntity httpEntity = httpResponse.getEntity();
String createResult = EntityUtils.toString(httpEntity, "UTF-8");
String errorMessage = "새로 추가됨:" + creativeAudit.getGeoid() + "출,状态码:" + statusCode + "; " + createResult;
result.put("실패", errorMessage);
}
} 잡기 (예외 ue) {
ue.printStackTrace();
result.put("실패했습니다", "주의 깊게 진행되었습니다!");
}
/*
creativeAudit.setUuid("189-"+creativeAudit.getGeoid());
result.put("성공",creativeAudit);
*/
결과 반환;
}