Git Product home page Git Product logo

simple_net_framework's Introduction

# SimpleNet网络框架 SimpleNet是一个简单的Android网络框架,该框架的结构类似Volley,该框架是为了让不太熟悉框架开发或者说不太了解Android网络编程的同学学习使用。它没有经过测试,因此不太建议运用在您的项目中。当然,如果你觉得没有什么问题的话也可以直接使用在你的项目中。该框架可以以并发的形式执行网络请求,并且将结果投递给UI线程。更多介绍请参考教你写Android网络框架

使用示例

    // 1、构建请求队列
    RequestQueue queue = SimpleNet.newRequestQueue();  
  
	// 2、创建请求
    MultipartRequest multipartRequest = new MultipartRequest("你的url", new 	RequestListener<String>() {
                    @Override
                    public void onComplete(int stCode, String response, String errMsg) {
                        // 该方法执行在UI线程
                    }
                }); 
  
	// 3、添加各种参数
	// 添加header  
	multipartRequest.addHeader("header-name", "value");  
	  
	// 通过MultipartEntity来设置参数  
	MultipartEntity multi = multipartRequest.getMultiPartEntity();  
	// 文本参数  
	multi.addStringPart("location", "模拟的地理位置");  
	multi.addStringPart("type", "0");  
  
	Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.thumb);  
	// 直接从上传Bitmap  
	multi.addBinaryPart("images", bitmapToBytes(bitmap));  
	// 上传文件  
	multi.addFilePart("imgfile", new File("storage/emulated/0/test.jpg"));  


	// 4、将请求添加到队列中  
	queue.addRequest(multipartRequest); 
	
	
	// 返回JSONObject的请求
	//        JsonRequest jsonRequest  = new JsonRequest(HttpMethod.GET, "服务器地址", new RequestListener<JSONObject>() {
	//
	//            @Override
	//            public void onComplete(int stCode, JSONObject response, String errMsg) {
	//                
	//            }
	//            
	//        }) ;
	 

最后,记得在Activity销毁时关闭消息队列。

queue.stop();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.