0

I have a problem with getting direct link to video. I want to play it in my WebView/VideoView. How to send POST request and recieve answer with direct link from website which decode such things:

videotools.12pings.net

Is there any way to do that?

Example: put link in the website form - than click a button - direct link is ready under the button

Amit Prajapati
  • 13,525
  • 8
  • 62
  • 84
user2245026
  • 153
  • 3
  • 8

3 Answers3

0
            final HttpParams httpParameters = new BasicHttpParams();
            // Set the timeout in milliseconds until a connection is
            // established.
            HttpConnectionParams.setConnectionTimeout(httpParameters, 7000);

            // Set the default socket timeout (SO_TIMEOUT)
            // in milliseconds which is the timeout for waiting for data.
            HttpConnectionParams.setSoTimeout(httpParameters, 10000);

            HttpClient client = new DefaultHttpClient(httpParameters);
            HttpResponse response = client.execute(new HttpGet(path));
            HttpEntity entity = response.getEntity();
            InputStream imageContentInputStream = entity.getContent();

path is the variable that contains your URL

Stefano
  • 3,127
  • 2
  • 27
  • 33
  • Where in this code I pass link to video which I want to decode? I think this is method to connect and make HTTP GET. So, it doesn't solve my problem. – user2245026 Sep 13 '13 at 07:51
  • http://stackoverflow.com/questions/2938502/sending-post-data-in-android try to take a look to this – Stefano Sep 13 '13 at 08:02
  • I have already seen that post before asking question. But how can i send POST if I don't know path to script which will answer me? Like there: [new HttpPost("http://www.yoursite.com/script.php")] – user2245026 Sep 13 '13 at 08:07
0

I hope this will help you.. *You need to get httpcomponents-client-4.1.zip and apache-mime4j-0.6.1-bin.zip

Add apache-mime4j-0.6.1-bin.zip and httpclient-4.1.jar httpcore-4.1.jar httpmime-4.1.jar from the lib folder in httpcomponents-client-4.1.zip - See more at: http://blog.tacticalnuclearstrike.com/2010/01/using-multipartentity-in-android-applications/#sthash.N7qT8apH.dpuf*

try {
MultipartEntity multipart = new MultipartEntity(
                HttpMultipartMode.BROWSER_COMPATIBLE);
FormBodyPart office = new FormBodyPart("office",
                    new StringBody(getOffice));
            multipart.addPart(office);

            String imageCount = Integer.toString(drawableList.size());
            System.out.println("ImageCount : " + imageCount);

            FormBodyPart imgNo = new FormBodyPart("imgNo", new StringBody(
                    imageCount));
            multipart.addPart(imgNo);

        } catch (Exception e) {
            // TODO: handle exception
        }

        try {
            System.out.println("result : " + multipart.getContentLength());
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost(CommunicatorUrl.ADD_INCIDENT);
            httppost.setEntity(multipart);
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity();

            // print responce
            outPut = EntityUtils.toString(entity);


        } catch (Exception e) {
            Log.e("log_tag ******",
                    "Error in http connection " + e.toString());
        }

basically this MultipartEntity is useful for sending multiple images and datas to server using post method

Bebin T.N
  • 2,539
  • 1
  • 24
  • 28
0
String paramUsername = "username";
String paramPassword = "password";
System.out.println("*** doInBackground ** paramUsername " + paramUsername + " 
paramPassword :" + paramPassword);
HttpClient httpClient = new DefaultHttpClient();

HttpPost httpPost = new HttpPost("http://www.xxxxxxxxxxxxxx.php");

BasicNameValuePair usernameBasicNameValuePair = new BasicNameValuePair("ParamUsername", paramUsername);

BasicNameValuePair passwordBasicNameValuePAir = new BasicNameValuePair("paramPassword", paramPassword);

List<NameValuePair> nameValuePairList = new ArrayList<NameValuePair>();

nameValuePairList.add(usernameBasicNameValuePair);
nameValuePairList.add(passwordBasicNameValuePAir);

try {
    UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(nameValuePairList);
    httpPost.setEntity(urlEncodedFormEntity);


try {
        HttpResponse httpResponse = httpClient.execute(httpPost);
        InputStream inputStream = httpResponse.getEntity().getContent();

        InputStreamReader inputStreamReader = new InputStreamReader(inputStream);

    BufferedReader bufferedReader = new BufferedReader(inputStreamReader);

    StringBuilder stringBuilder = new StringBuilder();

    String bufferedStrChunk = null;

    while((bufferedStrChunk = bufferedReader.readLine()) != null){
        stringBuilder.append(bufferedStrChunk);
    }

    return stringBuilder.toString();

} catch (ClientProtocolException cpe) {
    System.out.println("First Exception caz of HttpResponese :" + cpe);
    cpe.printStackTrace();
} catch (IOException ioe) {
    System.out.println("Second Exception caz of HttpResponse :" + ioe);
    ioe.printStackTrace();
}

} catch (UnsupportedEncodingException uee) {
System.out.println("An Exception given because of UrlEncodedFormEntity argument :" + uee);
uee.printStackTrace();
}
Bebin T.N
  • 2,539
  • 1
  • 24
  • 28