Android访问WEBAPI,传递json-创新互联

public static String sendHttpRequestByPost(final String address,String encode,MatterReflectDTO dto){

成都做网站、网站建设、外贸营销网站建设的开发,更需要了解用户,从用户角度来建设网站,获得较好的用户体验。成都创新互联公司多年互联网经验,见的多,沟通容易、能帮助客户提出的运营建议。作为成都一家网络公司,打造的就是网站建设产品直销的概念。选择成都创新互联公司,不只是建站,我们把建站作为产品,不断的更新、完善,让每位来访用户感受到浩方产品的价值服务。

    String result = "";

    DefaultHttpClient defaultHttpClient = new DefaultHttpClient();

    HttpPost httpPost = new HttpPost(address);

    String jsonString = dto.toString();

    try {

      StringEntity stringEntity = new StringEntity(new GsonBuilder().create().toJson(dto));

      System.out.println(stringEntity.toString());

      httpPost.setEntity(stringEntity);

      httpPost.setHeader("Accept", "application/json");

      httpPost.setHeader("Content-type", "application/json");

      httpPost.setHeader("Accept-Encoding", "gzip");

      HttpResponse httpResponse = defaultHttpClient.execute(httpPost);

      System.out.println("请求结果:"+httpResponse.getStatusLine().getStatusCode());

      int code = httpResponse.getStatusLine().getStatusCode();

      if(code ==200){

        InputStream is = httpResponse.getEntity().getContent();

        result = "true";

      }

    } catch (UnsupportedEncodingException e) {

      e.printStackTrace();

    } catch (ClientProtocolException e) {

      e.printStackTrace();

    } catch (IOException e) {

      e.printStackTrace();

    }

    return result;

  }

服务器端使用的是.net暂时就不贴出来了,需要注意的是并不是通过参数传递的。

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


分享标题:Android访问WEBAPI,传递json-创新互联
浏览地址:http://myzitong.com/article/djeeoe.html