Asked  7 Months ago    Answers:  5   Viewed   51 times

I m new in android and i m creating a project like this tutorial and its showing the error like the following photo.Please help me out of this.enter image description here

 Answers

46

Your project's compileSdkVersion is set to 23. Apache's HttpClient library was removed from the Android SDK in API Level 23.

If you change your compileSdkVersion to 21, your app will compile cleanly. Or, there is a workaround to continue using HttpClient in Android 6.0 with Android Studio. However, for long-term development, you really need to move to something else for an HTTP API. That "something else" could be:

  • the built-in classic Java HttpUrlConnection
  • Apache's independent packaging of HttpClient for Android
  • OkHttp (my recommendation)
  • AndroidAsync

Or, depending upon the nature of your HTTP work, you might choose a library that supports higher-order operations (e.g., Retrofit for Web service APIs).

Wednesday, March 31, 2021
 
matthy
answered 7 Months ago
75

Problem

HttpURLConnection has no JavaScript support, but a needed cookie is generated using JavaScript.

Your call

String reqUrl = "http://zxccvvv.cuccfree.com/send_data.php";
URL url = new URL(reqUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();

fails, because the cookie __test is missing.

Fix

From a first glance at the JavaScript source the cookie seems to be constant for a given url, so it might be enough to set for a constant cookie:

String cookie = "__test=2bf7c15501c0ec57f8e41cb84871a69c";

URL url = new URL(reqUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(7000);
conn.setRequestMethod("GET");
conn.setRequestProperty("Cookie", cookie);

Alternative: Using a WebView we can grab the cookie, so this is the preferable approach, since it will not break, if the cookie changes and it is not much of a time delay:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    getCookie();

    if(cookie!=null) {
        new GetContacts().execute();
    }
}

private void getCookie(){
    CookieManager.setAcceptFileSchemeCookies(true);
    WebView wv = new WebView(getApplicationContext());
    wv.getSettings().setJavaScriptEnabled(true);
    wv.loadUrl(url);
    cookie = CookieManager.getInstance().getCookie("zxccvvv.cuccfree.com");
}

and set it as in above example:

conn.setRequestProperty("Cookie", cookie);

Output in logcat

Response from url: [{"0":"1","id":"1","1":"pertanyaan ke 1","ask":"pertanyaan ke 1"},{"0":"2","id":"2","1":"pertanyaan ke 2","ask":"pertanyaan ke 2"},{"0":"3","id":"3","1":"pertanyaan ke 3","ask":"pertanyaan ke 3"},{"0":"4","id":"4","1":"pertanyaan ke 4","ask":"pertanyaan ke 4"},{"0":"5","id":"5","1":"pertanyaan ke 5","ask":"pertanyaan ke 5"}]
Saturday, May 29, 2021
 
Wickethewok
answered 5 Months ago
40

where exactly do i need to place the php file

You need to place PHP file in server. (You can use localhost i.e., your machine but for devices outside you need to keep it on a webserver which you need to purchase a domain and hosting services.)

where and how i need to create the php file.

You can create a PHP file in you machine itself. Its as simple as creating a text file but with an extension of .php. Using a wamp on windows (LAMP for linux)you can test it. It has a MySQL in it. LAMP and WAMP will have apache server by default.

Soon after you are finished with writing you php code and testing you can transfer the files through FTP into your webserver. Now to configure the MySQL database you can actually use a control panel at the webserver.

You need to use URL for android application to link the PHP files in turn these PHP files interact with MysQL. for a login lets think like you have created a php file as login.php. On your localhost you can refer it to as http://localhost/myapp/login.php If you need to get it on a webserver which you purchase then you URL will have http://www.yourwebsite.com/myapp/login.php. note that myapp is just a folder where you have uploaded your php files.

Now its just a way by which you can actually have a PHP and MySQL for you android application. I think that tutorials have taught you about using php and mysql connections. For Data exchange you need to know about XML or JSON I think tutorials followed had given you an introduction about it.

You even have a plugin for eclipse to work with php. Just get a help over internet on how to install it. This video might help you.

Saturday, May 29, 2021
 
inieto
answered 5 Months ago
35

As per How to get Response Status Code with Selenium WebDriver in Selenium WebDriver there is no direct method to check the response status code, so we have to use another library. You can use Apache HttpClient or REST-assured library from Jayway.

httpResponseCodeViaGet()

To use the method httpResponseCodeViaGet() you have to download and use the following import:

import io.restassured.RestAssured;

And then you can use:

new HttpResponseCode().httpResponseCodeViaGet("http://www.google.com");

Solution

As an alternative you can use HttpURLConnection and openConnection() and you can use the following solution:

package demo;

import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class BrokenLinks {

    public static void main(String[] args) throws Exception {

        String sDriverPath = "C:\Utility\BrowserDrivers\chromedriver.exe";
        System.setProperty("webdriver.chrome.driver", sDriverPath);
        String statusCode;
        final String URL = "https://www.starwars.com/";
        WebDriver driver = new ChromeDriver();
        driver.get(URL);
        driver.manage().window().maximize();
        List<WebElement> socialMenu = driver.findElements(By.xpath("//div[@id='nav-external-links']//a")); 
        System.out.println("Total Amenities "  + socialMenu.size());
        for (WebElement e : socialMenu)
        {
            String href = e.getAttribute("href");
            System.out.println(e.getAttribute("href"));
            HttpURLConnection connection = (HttpURLConnection) new URL(href).openConnection();
            connection.connect();
            statusCode = connection.getResponseMessage();
            connection.disconnect();
            if(!statusCode.contains("200")) {
                System.out.println(href + " gave a response code of " + statusCode);
            }
        }
    }
}
Saturday, July 31, 2021
 
ysquared
answered 3 Months ago
59

i could fix my problem, if someone have the same problem, i hope this can help them.

After you add the .jar to your java build path of your project, you have to import it to the report you want to use.

libraries

import it to your report

Then, to use the functions in your .jar, i had to write the path of the function like this "package.Class.Method", in my case for example was:

com.certuit.utils.RomanNumeral.roman(1)

com.certuit.utils is the package.

RomanNumeral the class

roman(1) is the method i want to use

This is what worked for me.

Monday, August 23, 2021
 
BaajiRao
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share