将Google下著名的网络方面的库Volley改写成Xamarin.Android版。
#改动的地方
var stringRequest = new StringRequest("http://www.baidu.com", (x) => { Log.Debug("Test", "String Request is Finished"); }, (x) => { Log.Debug("Test", x.ToString()); });
var webrequest = (HttpWebRequest)WebRequest.Create(request.Url); webrequest.Accept = Accept; webrequest.UserAgent = UserAgent; webrequest.Timeout = request.GetTimeoutMs(); if (Cookie != null) { webrequest.CookieContainer = Cookie; }
var cacheDir = Directory.CreateDirectory(context.CacheDir.Path + "/" + DEFAULT_CACHE_DIR); String userAgent = "volley/0"; try { String packageName = context.PackageName; var info = context.PackageManager.GetPackageInfo(packageName, 0); userAgent = packageName + "/" + info.VersionCode; }
var jsonRequest = new JsonRequest("http://172.16.101.20:8080/MUser/PostTest",new Test{ UName = "Test", UPass = "Test" },(x)=> { Log.Debug("Test",x.UName); }, (x)=> { Log.Debug("Test",x.ToString()); });
#示例代码
var requestQueue = Volley.NewRequestQueue(this); requestQueue.Start(); FindViewById(Resource.Id.btnString).Click += (e, s) => { var stringRequest = new StringRequest("http://www.baidu.com", (x) => { Log.Debug("Test", "String Request is Finished"); }, (x) => { Log.Debug("Test", x.ToString()); }); requestQueue.Add(stringRequest); }; FindViewById (Resource.Id.btnJson).Click += (sender, e) => { //该测试需要开发人员搭建一个简单的web端 var jsonRequest = new JsonRequest("http://172.16.101.20:8080/MUser/PostTest",new Test{ UName = "Test", UPass = "Test" },(x)=> { Log.Debug("Test",x.UName); }, (x)=> { Log.Debug("Test",x.ToString()); }); requestQueue.Add(jsonRequest); };
#更新记录
- v1.0 2015-4-15
- 通过String与Json测试
- 暂时未加入ImageRequest