Jump to content

send text file from javaapplication to php


mariam

Recommended Posts

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.