本文整理汇总了Java中org.apache.http.client.utils.URIUtils.createURI方法的典型用法代码示例。如果您正苦于以下问题:Java URIUtils.createURI方法的具体用法?Java URIUtils.createURI怎么用?Java URIUtils.createURI使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.client.utils.URIUtils
的用法示例。
在下文中一共展示了URIUtils.createURI方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createURI
import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
/**
* @param query
* e.g. "/issues.xml"
* @return URI with auth parameter "key" if not in "basic auth mode.
*/
private URI createURI(String query,
Collection<? extends NameValuePair> origParams) {
final List<NameValuePair> params = new ArrayList<NameValuePair>(
origParams);
if (apiAccessKey != null) {
params.add(new BasicNameValuePair("key", apiAccessKey));
}
URI uri;
try {
URL url = baseURL;
String path = url.getPath();
if (!query.isEmpty()) {
path += "/" + query;
}
uri = URIUtils.createURI(url.getProtocol(), url.getHost(),
url.getPort(), path,
URLEncodedUtils.format(params, "UTF-8"), null);
} catch (URISyntaxException e) {
throw new RedmineInternalError(e);
}
return uri;
}
示例2: doGet
import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
/**
* Make a GET request and append the Map of parameters onto the query string.
* @param address the fully qualified URL to make the request to
* @param parameters the Map of parameters, ie key,value pairs
* @return
*/
private String doGet(String address, Map<String, String> parameters){
try {
List<NameValuePair> queryParams = new ArrayList<NameValuePair>();
for (Map.Entry<String,String> entry : parameters.entrySet()) {
queryParams.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
}
URI uri = URIUtils.createURI(null, address, -1, null, URLEncodedUtils.format(queryParams, "UTF-8"), null);
log.info(uri.toString());
return doGet(uri.toString());
} catch (URISyntaxException e) {
log.error(e.getClass() + ":" + e.getMessage());
}
return null;
}
示例3: loadTopics
import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
@Override
protected ArrayList<? extends IListItem> loadTopics(Client client, ListInfo listInfo) throws IOException, ParseException, URISyntaxException {
SharedPreferences prefs = App.getInstance().getPreferences();
if (mUrl == null) {
List<NameValuePair> qparams = new ArrayList<NameValuePair>();
qparams.add(new BasicNameValuePair("showforum", getForumId()));
qparams.add(new BasicNameValuePair("sort_key", prefs.getString(getListName() + ".sort_key", "last_post")));
qparams.add(new BasicNameValuePair("sort_by", prefs.getString(getListName() + ".sort_by", "Z-A")));
qparams.add(new BasicNameValuePair("prune_day", prefs.getString(getListName() + ".prune_day", "100")));
qparams.add(new BasicNameValuePair("topicfilter", prefs.getString(getListName() + ".topicfilter", "all")));
qparams.add(new BasicNameValuePair("st", Integer.toString(listInfo.getFrom())));
URI uri = URIUtils.createURI("http", "4pda.ru", -1, "/forum/index.php",
URLEncodedUtils.format(qparams, "UTF-8"), null);
mUrl = uri.toString();
} else {
mUrl = mUrl.replaceAll("&st=\\d+", "").concat("&st=" + mListInfo.getFrom());
}
ArrayList<Topic> res = TopicsApi.getForumTopics(client, mUrl,getForumId(),
prefs.getBoolean(getListName() + ".unread_in_top", false),
mListInfo);
mUrl = Client.getInstance().getRedirectUri() != null ? Client.getInstance().getRedirectUri().toString() : mUrl;
return res;
}
示例4: pinFavorite
import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
public static String pinFavorite(IHttpClient httpClient, String topicId, String trackType) throws ParseException, IOException, URISyntaxException {
FavTopic favTopic = findTopicInFav(httpClient, topicId);
if (favTopic == null) {
return "Тема не найдена в избранном";
}
List<NameValuePair> qparams = new ArrayList<>();
qparams.add(new BasicNameValuePair("act", "fav"));
qparams.add(new BasicNameValuePair("selectedtids", favTopic.getTid()));
qparams.add(new BasicNameValuePair("tact", trackType));
URI uri = URIUtils.createURI("http", "4pda.ru", -1, "/forum/index.php",
URLEncodedUtils.format(qparams, "UTF-8"), null);
httpClient.performGet(uri.toString());
return TRACK_TYPE_PIN.equals(trackType) ? "Тема закреплена" : "Тема откреплена";
}
示例5: getAllScoresFromServer
import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
public static String getAllScoresFromServer(String serverIP, int serverPort) throws URISyntaxException, IOException {
URI uri = URIUtils.createURI("http", serverIP, serverPort, "/getScores", null, null);
URL url = uri.toURL();
URLConnection conn = url.openConnection();
InputStream is = conn.getInputStream();
StringWriter writer = new StringWriter();
IOUtils.copy(is, writer);
String response = writer.toString();
JSONObject jsonObject = new JSONObject(response);
System.out.println(response);
return jsonObject.toString();
}
示例6: doPost
import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
protected static MDSResult doPost(String scheme, String host, int port,
String path,
List<NameValuePair> postData) throws UnsupportedEncodingException{
URI uri = null;
try {
uri = URIUtils.createURI(scheme, host, port, path, null, null);
} catch (URISyntaxException e) {
e.printStackTrace();
throw new IllegalArgumentException(String.format("Can not post to mds: %s, %s, %d, %s", scheme,host,port,path),e);
}
Log.d(TAG, "doPost() uri: " + uri.toASCIIString());
HttpPost post = new HttpPost(uri);
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(postData, "UTF-8");
post.setEntity(entity);
return MDSInterface2.doExecute(post);
}
示例7: getInputStream
import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
@Override
public InputStream getInputStream() throws IOException {
try {
int port = m_url.getPort() > 0 ? m_url.getPort() : m_url.getDefaultPort();
String[] userInfo = m_url.getUserInfo() == null ? null : m_url.getUserInfo().split(":");
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(URIUtils.createURI(m_url.getProtocol(), m_url.getHost(), port, m_url.getPath(), m_url.getQuery(), null));
if (userInfo != null) {
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(userInfo[0], userInfo[1]);
request.addHeader(BasicScheme.authenticate(credentials, "UTF-8", false));
}
HttpResponse response = client.execute(request);
return new ByteArrayInputStream(EntityUtils.toByteArray(response.getEntity()));
} catch (Exception e) {
throw new IOException("Can't retrieve " + m_url.getPath() + " from " + m_url.getHost() + " because " + e.getMessage());
}
}
示例8: setQueryParameters
import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
public void setQueryParameters(List<NameValuePair> parms) {
URI uri = this.getURI();
URI uriWithQueryString = null;
try {
String query = URLEncodedUtils.format(parms, "UTF-8");
uriWithQueryString = URIUtils.createURI(
uri.getScheme(),
uri.getHost(),
uri.getPort(),
uri.getPath(),
// Do we need to merge any existing query params?
// Probably not... shouldn't be any.
query,
uri.getFragment()
);
this.setURI(uriWithQueryString);
} catch (URISyntaxException e) {
ThreadCategory.getInstance("Cannot add query parameters to URI: " + this.getClass()).warn(e.getMessage(), e);
}
}
示例9: testUri
import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
@org.junit.Test
public void testUri() throws Exception{
String param = "param1=" + URLEncoder.encode("中国", "UTF-8") + "¶m2=value2";
URI uri = URIUtils.createURI("http", "localhost", 8080,
"/sshsky/index.html", param, null);
System.out.println(uri);
}
示例10: markForumAsRead
import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
public static void markForumAsRead(IHttpClient httpClient, CharSequence forumId) throws Throwable {
List<NameValuePair> qparams = new ArrayList<NameValuePair>();
qparams.add(new BasicNameValuePair("act", "login"));
qparams.add(new BasicNameValuePair("CODE", "04"));
qparams.add(new BasicNameValuePair("f", forumId.toString()));
qparams.add(new BasicNameValuePair("fromforum", forumId.toString()));
URI uri = URIUtils.createURI("http", "4pda.ru", -1, "/forum/index.php",
URLEncodedUtils.format(qparams, "UTF-8"), null);
httpClient.performGet(uri.toString());
}
示例11: loginUriCreator
import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
public static URI loginUriCreator(String server, int port, String username, String password) throws URISyntaxException {
List<BasicNameValuePair> params = new ArrayList<>();
if (username != null && !username.isEmpty()) {
params.add(new BasicNameValuePair("username", username));
}
if (password != null && !password.isEmpty()) {
params.add(new BasicNameValuePair("password", password));
}
return URIUtils.createURI("http", server, port, "/login",
URLEncodedUtils.format(params, "UTF-8"), null);
}
示例12: signUpUriCreator
import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
public static URI signUpUriCreator(String server, int port, String username, String password) throws URISyntaxException {
List<BasicNameValuePair> params = new ArrayList<>();
if (username != null && !username.isEmpty()) {
params.add(new BasicNameValuePair("username", username));
}
if (password != null && !password.isEmpty()) {
params.add(new BasicNameValuePair("password", password));
}
return URIUtils.createURI("http", server, port, "/signup",
URLEncodedUtils.format(params, "UTF-8"), null);
}
示例13: sendUserScoreToServer
import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
/**
* Submit user's score to server. return true if success
* @param username User's username
* @param score User's score
* @param serverIP Server IP
* @param serverPort Server Port
* @return Return true if success, false otherwise
*/
public static boolean sendUserScoreToServer(String username, String score, String serverIP, int serverPort) throws URISyntaxException, IOException {
List<BasicNameValuePair> params = new ArrayList<>();
if (username != null && !username.isEmpty()) {
params.add(new BasicNameValuePair("username", username));
}
if (score != null && !score.isEmpty()) {
params.add(new BasicNameValuePair("score", score));
}
URI uri = URIUtils.createURI("http", serverIP, serverPort, "/submitScore", URLEncodedUtils.format(params, "UTF-8"), null);
URL url = uri.toURL();
URLConnection conn = url.openConnection();
InputStream is = conn.getInputStream();
StringWriter writer = new StringWriter();
IOUtils.copy(is, writer);
String response = writer.toString();
JSONObject jsonObject = new JSONObject(response);
System.out.println(response);
return jsonObject.getString("response").compareTo("OK") == 0;
}
示例14: getHttpGetRequest
import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
/**
*
* @param scheme
* @param host
* @param port
* @param path
* @param queryParams
* @return
* @throws IllegalArgumentException
*/
public static HttpGet getHttpGetRequest(String scheme, String host, int port,
String path, List<NameValuePair> queryParams, Header header)
{
try{
URI uri = URIUtils.createURI(scheme, host, port, path,
URLEncodedUtils.format(queryParams, "UTF-8"), null);
HttpGet get = new HttpGet(uri);
get.addHeader(header);
return get;
} catch (URISyntaxException e) {
throw new IllegalArgumentException(e);
}
}
示例15: createURI
import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
private static URI createURI(final String scheme,
final String path,
final List<NameValuePair> params)
throws Exception
{
final String host = path.startsWith("/v2/") ? API_HOST_V2 : API_HOST;
return URIUtils.createURI(scheme, host, API_PORT, path, URLEncodedUtils.format(params, "UTF-8"), null);
}