Open-source Android development framework ------- PowerFramework experiences (5) network requests for HTTPRequest and. netframework open-source
GET request example
// All parameters use Bundle, and putStringBundle = new bundle (); Bundle. putString ("username", "RederXuGet"); bundle. putString ("password", "farmerGet"); // urlString url = "http://www.baidu.com"; // initiate the request HTTPRequest. GET (this, url, bundle, new onRequestOverListener () {@ Override public void onRequestOver (String result) {// return result (or error cause) Log. e ("onRequestOver", result );}});
The post request and get request are written in the same way, except that the call method is different.
POST request example
// All parameters use Bundle, and putStringBundle = new bundle (); Bundle. putString ("username", "RederXuGet"); bundle. putString ("password", "farmerGet"); // urlString url = "http://www.baidu.com"; // initiate the request HTTPRequest. POST (this, url, bundle, new onRequestOverListener () {@ Override public void onRequestOver (String result) {// return result (or error cause) Log. e ("onRequestOver", result );}});
File Download
String url = "http: // 192.168.1.174: 8020/video1.mp4"; String path = "/mnt/sdcard/"; HTTPRequest. fileDownload (url, path, true, new onFileDownloadListener () {@ Override public void onDownloading (int max, int progress) {// TODO Auto-generated method stub Log. e ("download progress", progress + "/" + max) ;}@ Override public void onDownloadOver (String result) {Log. e ("download completed, storage location:", result );}});
File Upload
String uploadUrl = "http: // 192.168.1.174: 8020/android/FileUpload. php "; String filePath ="/mnt/sdcard/screenshot.png "; HTTPRequest. uploadFile (uploadUrl, filePath, new onRequestOverListener () {@ Override public void onRequestOver (String result) {// Log of the information returned after the Server Upload is successful. e ("upload", result );}});
Framework and DEMO file http://www.ideayapai.com/Application/Home/View/default/PowerFamily/index-2.htm
Welcome to the QQ Group for discussion: 575026537