本文整理汇总了Java中cz.msebera.android.httpclient.NameValuePair类的典型用法代码示例。如果您正苦于以下问题:Java NameValuePair类的具体用法?Java NameValuePair怎么用?Java NameValuePair使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NameValuePair类属于cz.msebera.android.httpclient包,在下文中一共展示了NameValuePair类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sanitizeICalUri
import cz.msebera.android.httpclient.NameValuePair; //导入依赖的package包/类
private String sanitizeICalUri(Uri uri) {
try {
URIBuilder b = new URIBuilder(uri.toString());
List<NameValuePair> params = b.getQueryParams();
b.clearParameters();
for (NameValuePair param : params) {
if (param.getName().equals("uid") || param.getName().equals("key")) {
b.addParameter(param.getName(), "hidden");
} else {
b.addParameter(param.getName(), param.getValue());
}
}
return b.toString();
} catch (java.net.URISyntaxException e) {
return "<URI parsing error>";
}
}
示例2: putWikiPage
import cz.msebera.android.httpclient.NameValuePair; //导入依赖的package包/类
/**
* Replaces an entire wiki page
*
* @param httpclient an active HTTP session
* @param pagename the name of the wiki page
* @param content the new content of the wiki page to be submitted
* @param formfields a hashmap with the fields needed (besides pagename and content; those will be filled in this method)
* @throws WikiException problem with the wiki, translate the ID
* @throws Exception anything else happened, use getMessage
*/
public static void putWikiPage(@NonNull CloseableHttpClient httpclient,
@NonNull String pagename, String content,
@NonNull HashMap<String, String> formfields) throws Exception {
// If there's no edit token in the hash map, we can't do anything.
if(!formfields.containsKey("token")) {
throw new WikiException(R.string.wiki_error_protected);
}
HttpPost httppost = new HttpPost(WIKI_API_URL);
ArrayList<NameValuePair> nvps = new ArrayList<>();
nvps.add(new BasicNameValuePair("action", "edit"));
nvps.add(new BasicNameValuePair("title", pagename));
nvps.add(new BasicNameValuePair("text", content));
nvps.add(new BasicNameValuePair("format", "xml"));
for(String s : formfields.keySet()) {
nvps.add(new BasicNameValuePair(s, formfields.get(s)));
}
httppost.setEntity(new UrlEncodedFormEntity(nvps, "utf-8"));
getWikiResponse(httpclient, httppost);
// And really, that's it. We're done!
}
示例3: deletePost
import cz.msebera.android.httpclient.NameValuePair; //导入依赖的package包/类
@Override
public String deletePost(DeletePostModel model, ProgressListener listener, CancellableTask task) throws Exception {
String url = getUsingUrl() + "cgi/delete";
List<NameValuePair> pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair("board", model.boardName));
pairs.add(new BasicNameValuePair("delete_" + model.postNumber, model.postNumber));
pairs.add(new BasicNameValuePair("task", "delete"));
pairs.add(new BasicNameValuePair("password", model.password));
HttpRequestModel request = HttpRequestModel.builder().setPOST(new UrlEncodedFormEntity(pairs, "UTF-8")).setNoRedirect(true).build();
HttpResponseModel response = null;
try {
response = HttpStreamer.getInstance().getFromUrl(url, request, httpClient, null, task);
if (response.statusCode == 302) {
return null;
}
throw new Exception(response.statusCode + " - " + response.statusReason);
} finally {
if (response != null) response.release();
}
}
示例4: checkCaptcha
import cz.msebera.android.httpclient.NameValuePair; //导入依赖的package包/类
private void checkCaptcha(String answer, CancellableTask task) throws Exception {
try {
if (torCaptchaCookie == null) throw new Exception("Invalid captcha");
String url = getUsingUrl() + "dnsbls_bypass.php";
List<NameValuePair> pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair("captcha_text", answer));
pairs.add(new BasicNameValuePair("captcha_cookie", torCaptchaCookie));
HttpRequestModel rqModel = HttpRequestModel.builder().setPOST(new UrlEncodedFormEntity(pairs, "UTF-8")).setTimeout(30000).build();
String response = HttpStreamer.getInstance().getStringFromUrl(url, rqModel, httpClient, null, task, true);
if (response.contains("Error") && !response.contains("Success")) throw new HttpWrongStatusCodeException(400, "400");
needTorCaptcha = false;
} catch (HttpWrongStatusCodeException e) {
if (task != null && task.isCancelled()) throw new InterruptedException("interrupted");
if (e.getStatusCode() == 400) throw new Exception("You failed the CAPTCHA");
throw e;
}
}
示例5: uploadFiles
import cz.msebera.android.httpclient.NameValuePair; //导入依赖的package包/类
/**
* Upload files with {@link com.loopj.android.http.SyncHttpClient}
*
* @param url
* @param paramsList
* @param fileParams
* @param files
* @param responseHandler
*/
public static void uploadFiles(String url, List<NameValuePair> paramsList, String fileParams, List<File> files, AsyncHttpResponseHandler responseHandler) throws Exception {
SyncHttpClient syncHttpClient = new SyncHttpClient();
RequestParams params = new RequestParams();
if (BasicUtils.judgeNotNull(paramsList)) {
for (NameValuePair nameValuePair : paramsList) {
params.put(nameValuePair.getName(), nameValuePair.getValue());
}
}
if (BasicUtils.judgeNotNull(files))
params.put(fileParams, files);
syncHttpClient.setTimeout(timeout);
syncHttpClient.post(url, params, responseHandler);
}
示例6: parseEntityParams
import cz.msebera.android.httpclient.NameValuePair; //导入依赖的package包/类
private ParameterList parseEntityParams() {
cz.msebera.android.httpclient.HttpEntity entity = null;
List<cz.msebera.android.httpclient.NameValuePair> parameters = null;
try{
entity = ((HttpEntityEnclosingRequestBase) httpUriRequest).getEntity();
parameters = new ArrayList<NameValuePair>( URLEncodedUtils.parse(entity));
} catch (Exception e) {
return new ParameterList();
}
ParameterList list = new ParameterList();
for (NameValuePair pair : parameters) {
list.add(pair.getName(), pair.getValue());
}
return list;
}
示例7: getQuery
import cz.msebera.android.httpclient.NameValuePair; //导入依赖的package包/类
@NonNull
public static String getQuery(List<NameValuePair> params) throws UnsupportedEncodingException {
StringBuilder result = new StringBuilder();
boolean first = true;
for (NameValuePair pair : params) {
if (first) first = false;
else result.append("&");
result.append(URLEncoder.encode(pair.getName(), "UTF-8"));
result.append("=");
result.append(URLEncoder.encode(pair.getValue(), "UTF-8"));
}
return result.toString();
}
示例8: doInBackground
import cz.msebera.android.httpclient.NameValuePair; //导入依赖的package包/类
@Override
protected Void doInBackground(String... message) {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.instruman.it/assets/feedback/update.php");
try {
//add data
List<NameValuePair> nameValuePairs = new ArrayList<>(1);
nameValuePairs.add(new BasicNameValuePair("stars", message[0]));
nameValuePairs.add(new BasicNameValuePair("message", message[1]));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
//execute http post
HttpResponse response = httpclient.execute(httppost);
} catch (Exception e) {
}
return null;
}
示例9: deletePost
import cz.msebera.android.httpclient.NameValuePair; //导入依赖的package包/类
@Override
public String deletePost(DeletePostModel model, ProgressListener listener, CancellableTask task) throws Exception {
String url = getUsingUrl() + "post.php";
List<NameValuePair> pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair("board", model.boardName));
pairs.add(new BasicNameValuePair("delete_" + model.postNumber, "on"));
if (model.onlyFiles) pairs.add(new BasicNameValuePair("file", "on"));
pairs.add(new BasicNameValuePair("password", model.password));
pairs.add(new BasicNameValuePair("delete", getDeleteFormValue(model)));
pairs.add(new BasicNameValuePair("reason", ""));
UrlPageModel refererPage = new UrlPageModel();
refererPage.type = UrlPageModel.TYPE_THREADPAGE;
refererPage.chanName = getChanName();
refererPage.boardName = model.boardName;
refererPage.threadNumber = model.threadNumber;
Header[] customHeaders = new Header[] { new BasicHeader(HttpHeaders.REFERER, buildUrl(refererPage)) };
HttpRequestModel rqModel = HttpRequestModel.builder().
setPOST(new UrlEncodedFormEntity(pairs, "UTF-8")).setCustomHeaders(customHeaders).setNoRedirect(true).build();
HttpResponseModel response = null;
try {
response = HttpStreamer.getInstance().getFromUrl(url, rqModel, httpClient, listener, task);
if (response.statusCode == 200 || response.statusCode == 400 || response.statusCode == 303) {
ByteArrayOutputStream output = new ByteArrayOutputStream(1024);
IOUtils.copyStream(response.stream, output);
String htmlResponse = output.toString("UTF-8");
Matcher errorMatcher = ERROR_PATTERN.matcher(htmlResponse);
if (errorMatcher.find()) throw new Exception(errorMatcher.group(1));
return null;
}
throw new Exception(response.statusCode + " - " + response.statusReason);
} finally {
if (response != null) response.release();
}
}
示例10: reportPost
import cz.msebera.android.httpclient.NameValuePair; //导入依赖的package包/类
@Override
public String reportPost(DeletePostModel model, ProgressListener listener, CancellableTask task) throws Exception {
String url = getUsingUrl() + "post.php";
List<NameValuePair> pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair("board", model.boardName));
pairs.add(new BasicNameValuePair("delete_" + model.postNumber, "on"));
pairs.add(new BasicNameValuePair("password", ""));
pairs.add(new BasicNameValuePair("reason", model.reportReason));
pairs.add(new BasicNameValuePair("report", getReportFormValue(model)));
UrlPageModel refererPage = new UrlPageModel();
refererPage.type = UrlPageModel.TYPE_THREADPAGE;
refererPage.chanName = getChanName();
refererPage.boardName = model.boardName;
refererPage.threadNumber = model.threadNumber;
Header[] customHeaders = new Header[] { new BasicHeader(HttpHeaders.REFERER, buildUrl(refererPage)) };
HttpRequestModel rqModel = HttpRequestModel.builder().
setPOST(new UrlEncodedFormEntity(pairs, "UTF-8")).setCustomHeaders(customHeaders).setNoRedirect(true).build();
HttpResponseModel response = null;
try {
response = HttpStreamer.getInstance().getFromUrl(url, rqModel, httpClient, listener, task);
if (response.statusCode == 200 || response.statusCode == 400 || response.statusCode == 303) {
ByteArrayOutputStream output = new ByteArrayOutputStream(1024);
IOUtils.copyStream(response.stream, output);
String htmlResponse = output.toString("UTF-8");
Matcher errorMatcher = ERROR_PATTERN.matcher(htmlResponse);
if (errorMatcher.find()) throw new Exception(errorMatcher.group(1));
return null;
}
throw new Exception(response.statusCode + " - " + response.statusReason);
} finally {
if (response != null) response.release();
}
}
示例11: deletePost
import cz.msebera.android.httpclient.NameValuePair; //导入依赖的package包/类
@Override
public String deletePost(DeletePostModel model, ProgressListener listener, CancellableTask task) throws Exception {
String url = getBoardScriptUrl(model);
List<? extends NameValuePair> pairs = getDeleteFormAllValues(model);
HttpRequestModel request = HttpRequestModel.builder().setPOST(new UrlEncodedFormEntity(pairs, "UTF-8")).setNoRedirect(true).build();
String result = HttpStreamer.getInstance().getStringFromUrl(url, request, httpClient, listener, task, false);
checkDeletePostResult(model, result);
return null;
}
示例12: reportPost
import cz.msebera.android.httpclient.NameValuePair; //导入依赖的package包/类
@Override
public String reportPost(DeletePostModel model, ProgressListener listener, CancellableTask task) throws Exception {
String url = getBoardScriptUrl(model);
List<? extends NameValuePair> pairs = getReportFormAllValues(model);
HttpRequestModel request = HttpRequestModel.builder().setPOST(new UrlEncodedFormEntity(pairs, "UTF-8")).setNoRedirect(true).build();
String result = HttpStreamer.getInstance().getStringFromUrl(url, request, httpClient, listener, task, false);
checkReportPostResult(model, result);
return null;
}
示例13: getDeleteFormAllValues
import cz.msebera.android.httpclient.NameValuePair; //导入依赖的package包/类
protected List<? extends NameValuePair> getDeleteFormAllValues(DeletePostModel model) throws Exception {
List<NameValuePair> pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair("board", model.boardName));
pairs.add(new BasicNameValuePair("post[]", model.postNumber));
if (model.onlyFiles) pairs.add(new BasicNameValuePair("fileonly", "on"));
pairs.add(new BasicNameValuePair("postpassword", model.password));
pairs.add(new BasicNameValuePair("deletepost", getDeleteFormValue(model)));
return pairs;
}
示例14: getReportFormAllValues
import cz.msebera.android.httpclient.NameValuePair; //导入依赖的package包/类
protected List<? extends NameValuePair> getReportFormAllValues(DeletePostModel model) throws Exception {
List<NameValuePair> pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair("board", model.boardName));
pairs.add(new BasicNameValuePair("post[]", model.postNumber));
pairs.add(new BasicNameValuePair("reportreason", model.reportReason));
pairs.add(new BasicNameValuePair("reportpost", getReportFormValue(model)));
return pairs;
}
示例15: deletePost
import cz.msebera.android.httpclient.NameValuePair; //导入依赖的package包/类
@Override
public String deletePost(DeletePostModel model, ProgressListener listener, CancellableTask task) throws Exception {
String url = getDomainUrl() + model.boardName + "/delete";
String threadAPIUrl = getDomainUrl() + "api/thread/" + model.boardName + "/" + model.threadNumber + ".json";
String threadId = Long.toString(downloadJSONObject(threadAPIUrl, false, null, task).getLong("thread_id"));
List<NameValuePair> pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair(model.postNumber, threadId));
pairs.add(new BasicNameValuePair("task", "delete"));
pairs.add(new BasicNameValuePair("password", model.password));
HttpRequestModel request = HttpRequestModel.builder().setPOST(new UrlEncodedFormEntity(pairs, "UTF-8")).setNoRedirect(true).build();
HttpResponseModel response = null;
try {
response = HttpStreamer.getInstance().getFromUrl(url, request, httpClient, null, task);
if (response.statusCode == 200) {
ByteArrayOutputStream output = new ByteArrayOutputStream(1024);
IOUtils.copyStream(response.stream, output);
String htmlResponse = output.toString("UTF-8");
Matcher errorMatcher = Pattern.compile("<center><h2>([^<]*)<").matcher(htmlResponse);
if (errorMatcher.find()) throw new Exception(errorMatcher.group(1));
}
} finally {
if (response != null) response.release();
saveHanabiraCookie();
}
return null;
}