No data posted to server from android -
i'm trying implement sample form multiple images submit php server.below code snippets used implement
when submit
b3.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { if(!(selectedpath1.trim().equalsignorecase("none")) && !(selectedpath2.trim().equalsignorecase("none"))){ progressdialog = progressdialog.show(mainactivity.this, "", "uploading files server.....", false); thread thread=new thread(new runnable(){ public void run(){ dofileupload(); runonuithread(new runnable(){ public void run() { if(progressdialog.isshowing()) progressdialog.dismiss(); } }); } }); thread.start(); }else{ toast.maketext(getapplicationcontext(),"please select 2 files upload.", toast.length_short).show(); } } });
dofileupload()
private void dofileupload(){ file file1 = new file(selectedpath1); file file2 = new file(selectedpath2); string urlstring = "http://url/api"; try { httpclient client = new defaulthttpclient(); httppost post = new httppost(urlstring); filebody bin1 = new filebody(file1); filebody bin2 = new filebody(file2); multipartentity reqentity = new multipartentity(httpmultipartmode.browser_compatible); reqentity.addpart("image1", bin1); reqentity.addpart("image2", bin2); reqentity.addpart("section", new stringbody("inventory")); reqentity.addpart("action", new stringbody("new")); reqentity.addpart("apron_id", new stringbody("465464f313164d6464fds64f6d4")); reqentity.addpart("nickname", new stringbody("test")); reqentity.addpart("location", new stringbody(2+"")); reqentity.addpart("manufacture", new stringbody(3+"")); reqentity.addpart("core_material", new stringbody("test")); reqentity.addpart("color", new stringbody("test")); reqentity.addpart("date_purchase", new stringbody("25/10/1991")); reqentity.addpart("uid_no", new stringbody("546345643465434554436554")); reqentity.addpart("serial", new stringbody("46544624463464423644634244545")); reqentity.addpart("batch", new stringbody("464546631313464")); reqentity.addpart("expiration", new stringbody("25/10/2091")); reqentity.addpart("garment_type", new stringbody("test")); reqentity.addpart("qty", new stringbody("4")); reqentity.addpart("user_id", new stringbody(2+"")); post.setentity(reqentity); httpresponse response = client.execute(post); resentity = response.getentity(); final string response_str = entityutils.tostring(resentity); if (resentity != null) { log.i("response",response_str); runonuithread(new runnable(){ public void run() { try { res.settextcolor(color.green); res.settext("n response server : n " + response_str); toast.maketext(getapplicationcontext(),"upload complete. check server uploads directory.", toast.length_long).show(); } catch (exception e) { e.printstacktrace(); } } }); } } catch (exception ex){ log.e("debug", "error: " + ex.getmessage(), ex); } }
app seems sent post data no data received @ server below php script
<?php require_once("../includes/dbconfig.php"); require_once("../includes/classes/general.php"); $status =1; $response=array(); $data=$_request; $action=$data['action']; $section=$_request['section']; file_put_contents("out.txt","\n".implode("\n",$_request)." \n ".implode("\n",$_files)." \n date ".date("y-d-m h:i:s"),file_append); if($section=="inventory") { if(empty($action)) { $response=array("status"=>0,"data"=>"no action found"); echo json_encode($response); exit; } require_once("classes/class_inventory.php"); $inventory = new inventory(); switch($action) { case 'new': $response=$inventory->action_inventory($_request); echo json_encode($response); exit; case 'get': $response=$inventory->get_inventory($_request); echo json_encode($response); exit; } }else { $response=array("status"=>0,"date"=>" no section found "); echo json_encode($response); exit; } ?>
screen shot of response
remove or comment code script. put following lines in
$section=$_request['section']; echo ( "section: (" . $section . ")\n"); $section=$_post['section']; echo ( "section: (" . $section . ")\n" ); if($section=="inventory") echo ("indeed section == inventory\n"); if($section==="inventory") echo ("indeed section === inventory\n");
tell result.
and please tell wrong in code.
Comments
Post a Comment