开发者

setting a background connection to a site

开发者 https://www.devze.com 2023-02-13 23:35 出处:网络
i am doing a application now that is able to read a message from a site now i am doing the part on deleting a message via a link

i am doing a application now that is able to read a message from a site

now i am doing the part on deleting a message via a link

the text is stored on http://www.example.com/test/file.txt i have a php script on http://www.example.com/test/delete.php which once the site is loaded, file.txt will become "" which is null

how do i create such a request to the site without alerting the user? it is working perfectly on the my comp browser

i have put this method into onLongClic开发者_JAVA技巧kListener

    public boolean onLongClick(View v)
{
    String webURL = "http://example.net/test/delete.php";
    URL url;
    try 
    {
        url = new URL(webURL);

        /* Open a connection to that URL. */
        HttpURLConnection ucon = (HttpURLConnection) url.openConnection();

        Context context = getApplicationContext();
        Toast toast = Toast.makeText(context, "Message Deleted!", Toast.LENGTH_SHORT);
        toast.show();
    } 

    catch (Exception e) 
    {
        e.printStackTrace();
    }
    return true;
}


i managed to find an answer after looking around for so long

          HttpClient httpclient = new DefaultHttpClient();  
          HttpPost httppost = new HttpPost(webURL);  

          // Execute HTTP Post Request  
          httpclient.execute(httppost);

used this to send a request to the delete.php which will turn the text file into a "" upon a Post request

0

精彩评论

暂无评论...
验证码 换一张
取 消