C/C++教程

android使用AsyncHttpClient发送请求

本文主要是介绍android使用AsyncHttpClient发送请求,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
package com.example.xxxx;

import android.util.Log;

import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;

import cz.msebera.android.httpclient.Header;

public class HttpClient {

    public static void senddata(String data) {

        String postUrl = "http://xxx:9091/get_video_list";

        RequestParams params = new RequestParams();
        params.put("data", data);
        AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
        try {
            asyncHttpClient.post(postUrl, params, new AsyncHttpResponseHandler() {
               @Override
               public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
                   Log.d("cxa", new String(responseBody));

               }

               @Override
               public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
                   Log.d("cxa",error.getMessage());

               }

           });
       }
       catch (Exception e){
           Log.d("cxa",e.getMessage());
       }


    }
}



这篇关于android使用AsyncHttpClient发送请求的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!