android - Not able to upload image to server using Httprequest library -
i have created app in user select image gallery , image uploaded server.i tried doing using httprequest library.but m not being able upload it.
code
httprequest request = httprequest.post ("https://beta135.hamarisuraksha.com/web/mobileapp/postimsafeprflpic.aspx").send ("mode=pp" + "&id=" + "8" + "&ext=.jpg" + f); request.part ("mode", "mode=pp"); request.part ("id", "&id=34588a34-e969-4723-84fe-e5409b66a5b7"); request.part ("ext", "&ext=.jpg"); request.part ("file", f); string response = request.body (); log.e ("image upload", "" + response); return response;
also if there other library can use work,plz lemme know.
try code , library add httpmime-4.1-beta1.jar :
string url = "your url"; httpclient client = new defaulthttpclient(); client.getparams().setparameter( coreprotocolpnames.protocol_version, httpversion.http_1_1); httppost postmethod = new httppost(url); multipartentity entity = new multipartentity(); entity.addpart("fname", new stringbody("xyz")); try { file file1 = new file("your image path"); filebody bin1 = new filebody(file1, "images/jpeg"); entity.addpart("file", bin1); postmethod.setentity(entity); httpresponse response; response = client.execute(postmethod); string result = entityutils.tostring(response.getentity()); } catch (exception e) { // todo auto-generated catch block e.printstacktrace(); }
Comments
Post a Comment