mariam Posted July 5, 2011 Share Posted July 5, 2011 hi, i want this java application to send a text file to my url. A java side script ive found is ' public class Web_Post extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Toast.makeText(this, "Just below setcontentview", Toast.LENGTH_LONG).show(); final byte[] buffer = new byte[1024]; File file = new File("./sdcard/Android/randomtext.txt"); try { HttpClient client = new DefaultHttpClient(); String postURL = "http://www.example.com/index.php?foo="+ buffer[1] +"bar&bla=blub"; postURL.concat(postURL + ";" + buffer[2]); HttpPost post = new HttpPost(postURL); Toast.makeText(this, "Inisde 'try' statement", Toast.LENGTH_LONG).show(); FileBody bin = new FileBody(file); MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); reqEntity.addPart("myFile", bin); post.setEntity(reqEntity); HttpResponse response = client.execute(post); HttpEntity resEntity = response.getEntity(); Toast.makeText(this, "Response and request made", Toast.LENGTH_LONG).show(); if (resEntity != null) { Log.i("RESPONSE",EntityUtils.toString(resEntity)); Toast.makeText(this, "Inside the if statement", Toast.LENGTH_LONG).show(); Toast.makeText(this, EntityUtils.toString(resEntity), Toast.LENGTH_LONG).show(); } } catch (Exception e) { e.printStackTrace(); } } } [/Code] I am looking for a php script on how to receive the text file at my website. please help Quote Link to comment https://forums.phpfreaks.com/topic/241153-send-text-file-from-javaapplication-to-php/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.