当前位置: 首页>>代码示例>>Java>>正文


Java HttpPost类代码示例

本文整理汇总了Java中cz.msebera.android.httpclient.client.methods.HttpPost的典型用法代码示例。如果您正苦于以下问题:Java HttpPost类的具体用法?Java HttpPost怎么用?Java HttpPost使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HttpPost类属于cz.msebera.android.httpclient.client.methods包,在下文中一共展示了HttpPost类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: putWikiPage

import cz.msebera.android.httpclient.client.methods.HttpPost; //导入依赖的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!
}
 
开发者ID:CaptainSpam,项目名称:geohashdroid,代码行数:36,代码来源:WikiUtils.java

示例2: execute

import cz.msebera.android.httpclient.client.methods.HttpPost; //导入依赖的package包/类
private JSONObject execute(HttpPost request, JSONObject payload) throws IOException, NetworkException, JSONException {
    setPayloadXsrf(payload);
    request.setEntity(new ByteArrayEntity(payload.toString().getBytes()));
    authenticateRequest(request);

    HttpResponse resp = client.execute(request, httpContext);
    StatusLine sl = resp.getStatusLine();
    if (sl.getStatusCode() != 200) throw new NetworkException(sl);

    return new JSONObject(EntityUtils.toString(resp.getEntity(), Charset.forName("UTF-8")));
}
 
开发者ID:devgianlu,项目名称:PlayConsoleAndroidAPI,代码行数:12,代码来源:PlayConsoleRequester.java

示例3: doInBackground

import cz.msebera.android.httpclient.client.methods.HttpPost; //导入依赖的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;
}
 
开发者ID:paolo-optc,项目名称:optc-mobile-db,代码行数:21,代码来源:FeedbackDialogFragment.java

示例4: PlayConsoleRequest

import cz.msebera.android.httpclient.client.methods.HttpPost; //导入依赖的package包/类
private PlayConsoleRequest(HttpPost request, JSONObject body) {
    this.request = request;
    this.body = body;
}
 
开发者ID:devgianlu,项目名称:PlayConsoleAndroidAPI,代码行数:5,代码来源:PlayConsoleRequest.java

示例5: build

import cz.msebera.android.httpclient.client.methods.HttpPost; //导入依赖的package包/类
public PlayConsoleRequest build() {
    if (url == null) throw new IllegalArgumentException("an url must be specified!");
    return new PlayConsoleRequest(new HttpPost(url), body);
}
 
开发者ID:devgianlu,项目名称:PlayConsoleAndroidAPI,代码行数:5,代码来源:PlayConsoleRequest.java

示例6: putWikiImage

import cz.msebera.android.httpclient.client.methods.HttpPost; //导入依赖的package包/类
/**
 * Uploads an image to the wiki
 *
 * @param httpclient  an active HTTP session, wiki login has to have happened before.
 * @param filename    the name of the new image file
 * @param description the description of the image. An initial description will be used as page content for the image's wiki page
 * @param formfields  a formfields hash as modified by getWikiPage containing an edittoken we can use (see the MediaWiki API for reasons why)
 * @param data        a ByteArray containing the raw image data (assuming jpeg encoding, currently).
 */
public static void putWikiImage(@NonNull CloseableHttpClient httpclient,
                                @NonNull String filename,
                                @NonNull String description,
                                @NonNull HashMap<String, String> formfields,
                                @NonNull byte[] data) throws Exception {
    if(!formfields.containsKey("token")) {
        throw new WikiException(R.string.wiki_error_unknown);
    }

    HttpPost httppost = new HttpPost(WIKI_API_URL);

    // First, we need an edit token.  Let's get one.
    ArrayList<NameValuePair> tnvps = new ArrayList<>();
    tnvps.add(new BasicNameValuePair("action", "query"));
    tnvps.add(new BasicNameValuePair("prop", "info"));
    tnvps.add(new BasicNameValuePair("intoken", "edit"));
    tnvps.add(new BasicNameValuePair("titles", "UPLOAD_AN_IMAGE"));
    tnvps.add(new BasicNameValuePair("format", "xml"));

    httppost.setEntity(new UrlEncodedFormEntity(tnvps, "utf-8"));

    WikiResponse response = getWikiResponse(httpclient, httppost);

    // Hopefully, a token exists.  If not, a problem exists.
    String token;
    Element page;
    try {
        page = DOMUtil.getFirstElement(response.rootElem, "page");
        token = DOMUtil.getSimpleAttributeText(page, "edittoken");
    } catch(Exception e) {
        throw new WikiException(R.string.wiki_error_xml);
    }

    // We very much need an edit token here.
    if(token == null) {
        throw new WikiException(R.string.wiki_error_xml);
    }

    // TOKEN GET!  Now we've got us enough to get our upload on!
    MultipartEntityBuilder builder = MultipartEntityBuilder.create()
            .addPart("action", new StringBody("upload", ContentType.TEXT_PLAIN))
            .addPart("filename", new StringBody(filename, ContentType.TEXT_PLAIN))
            .addPart("comment", new StringBody(description, ContentType.TEXT_PLAIN))
            .addPart("watch", new StringBody("true", ContentType.TEXT_PLAIN))
            .addPart("ignorewarnings", new StringBody("true", ContentType.TEXT_PLAIN))
            .addPart("token", new StringBody(token, ContentType.TEXT_PLAIN))
            .addPart("format", new StringBody("xml", ContentType.TEXT_PLAIN))
            .addPart("file", new ByteArrayBody(data, ContentType.create("image/jpeg", "utf-8"), filename));

    httppost.setEntity(builder.build());

    getWikiResponse(httpclient, httppost);
}
 
开发者ID:CaptainSpam,项目名称:geohashdroid,代码行数:63,代码来源:WikiUtils.java

示例7: post

import cz.msebera.android.httpclient.client.methods.HttpPost; //导入依赖的package包/类
/**
 * Perform a HTTP POST request and track the Android Context which initiated the request. Set
 * headers only for this request
 *
 * @param context         the Android Context which initiated the request.
 * @param url             the URL to send the request to.
 * @param headers         set headers only for this request
 * @param params          additional POST parameters to send with the request.
 * @param contentType     the content type of the payload you are sending, for example
 *                        application/json if sending a json payload.
 * @param responseHandler the response handler instance that should handle the response.
 * @return RequestHandle of future request process
 */
public RequestHandle post(Context context, String url, Header[] headers, RequestParams params, String contentType,
                          ResponseHandlerInterface responseHandler) {
    HttpEntityEnclosingRequestBase request = new HttpPost(getURI(url));
    if (params != null) request.setEntity(paramsToEntity(params, responseHandler));
    if (headers != null) request.setHeaders(headers);
    return sendRequest(httpClient, httpContext, request, contentType,
            responseHandler, context);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:AsyncHttpClient.java


注:本文中的cz.msebera.android.httpclient.client.methods.HttpPost类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。