Copy Code code as follows:
private static String URL = Propertiesloader.getproperty ("Allyes_server", false);
private static String username = Propertiesloader.getproperty ("Allyes_username", false);
private static String password = Propertiesloader.getproperty ("Allyes_password", false);
/**
* Add Creative
*
* @param creativeaudit
* @return
*/
public static map<string, object> addcreative (Creativeaudit creativeaudit) {
//name,width,height,type,creativetagid, Code,bindid
String type = "9";
if (Creativeaudit.getrelative_path (). toLowerCase (). EndsWith ("GIF" )
type = "10";
if (Creativeaudit.getrelative_path (). toLowerCase (). EndsWith ("SWF" )
type = "11";
map<string, object> result = new hashmap<string, object> () ;
String addurl = URL + "/creatives/add";
Defaulthttpclient httpclient = new Defaulthttpclient ();
Httpclient.getcredentialsprovider (). SetCredentials (Authscope.any, New usernamepasswordcredentials (username, password));
try {
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 entity = 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 ("Success", Creativeaudit);
} else {
Httpentity httpentity = httpresponse.getentity ();
String Createresult = entityutils.tostring (httpentity, "UTF-8");
String errormessage = "Add originality:" + creativeaudit.getgeoid () + "error, Status code:" + StatusCode + ";" + Createresult;
Result.put ("Failed", errormessage);
}
\ catch (Exception UE) {
Ue.printstacktrace ();
Result.put ("Failed", "the data submitted when adding the idea has a problem!");
}
/*
Creativeaudit.setuuid ("189-" +creativeaudit.getgeoid ());
Result.put ("Success", Creativeaudit);
*/
return result;
}