03-30-2016 04:16 AM
public class TestShareCreateSitePost {
public static void main(String[] args) throws Exception {
System.out.println(createSite());
}
private static String createSite() {
try {
DefaultHttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(
"http://localhost:8080/share/page/dologin");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("username", "admin"));
nameValuePairs.add(new BasicNameValuePair("password", "admin"));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
client.execute(post);
CookieStore cookieStore = client.getCookieStore();
client = new DefaultHttpClient();
client.setCookieStore(cookieStore);
post = new HttpPost(
"http://localhost:8080/share/service/modules/create-site");
post.setHeader("Content-Type", "application/json");
post.setEntity(new StringEntity(createSiteParameters(
"JavaTest-001", "Sito di test by JAVA", "JavaTest-001"),
"UTF-8"));
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String response = client.execute(post, responseHandler);
return response;
} catch (Exception e) {
e.printStackTrace();
}
return "Error!";
}
private static String createSiteParameters(String title,
String description, String shortName) {
String site = "{\"visibility\":\"PUBLIC\", "
+ "\"sitePreset\":\"site-dashboard\", " + "\"title\":\""
+ title + "\", " + "\"description\":\"" + description + "\", "
+ "\"shortName\":\"" + shortName + "\"}";
System.out.println(site);
return site;
}
}
04-08-2016 02:38 AM
04-18-2016 12:17 PM
import json
import requests
from json import JSONEncoder
try:
url = 'http://127.0.0.1:8080/share/page/dologin'
headers = {'content-type': 'application/x-www-form-urlencoded'}
post_data = {'username':'admin', 'password':'admin'}
r = requests.post(url, headers=headers,data=post_data)
r.encoding = 'UTF-8'
print r.status_code
except:
print 'hhhh'
get_response = requests.get('http://127.0.0.1:8080/share/service/modules/authenticated?a=user')
print get_response.status_code
url1='http://127.0.0.1:8080/share/service/modules/create-site'
shortName="sitepython"
jsonString = JSONEncoder().encode({
"shortName": shortName,
"Visiblity": "Public",
"sitePreset": "site-dashboard",
"title" : shortName,
"description" : shortName
})
headers = {'content-type': 'application/json',"Accept":"application/json"}
site = requests.post(url1,headers=headers,data=json.dumps(jsonString))
print site.status_code
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.