• AndroidPost向服务器提交数据


    Android 实现Post向服务器提交数据

    android客户端代码:

     

    public static String postData(String sUrl) {

    String destUrl = "";

    destUrl = sUrl;

    String sResult = "";

    // instantiate HttpPost object from the url address

    HttpEntityEnclosingRequestBase httpRequest = new HttpPost(destUrl);

    // the post name and value must be used as NameValuePair

      List params = new ArrayList();

      params.add(new BasicNameValuePair("id", "111111"));

      params.add(new BasicNameValuePair("title", "ttttttttttt"));

      params.add(new BasicNameValuePair("content", "ccccccccccccccc"));

      params.add(new BasicNameValuePair("img", "iiiiiiii"));

    try {

    httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));

    // execute the post and get the response from servers

    HttpResponse httpResponse = new DefaultHttpClient()

    .execute(httpRequest);

    if (httpResponse.getStatusLine().getStatusCode() == 200) {

    // get the result

    String strResult = EntityUtils.toString(httpResponse

    .getEntity());

    sResult = strResult;

    System.out.println(strResult);

    } else {

    System.out.println("Error Response"

    + httpResponse.getStatusLine().toString());

    }

    } catch (Exception e) {

    System.out.println("error occurs");

    }

    return sResult;

    }

    服务器端php代码:

  • 相关阅读:
    适用于Java和JavaScript的Codota AI自动完成
    Postgresql常用函数整理
    vue引入echarts地图的三种方式
    Linux下 tar 命令介绍
    如何并发执行Linux命令
    如何复用外部shell脚本
    shell 脚本中日期运算
    有问题找男人帮忙- Linux下man命令
    MySQL 排序规则简介
    再也不用担心 SSH 断开了
  • 原文地址:https://www.cnblogs.com/crane13/p/3150122.html
Copyright © 2020-2023  润新知