Note that there are some explanatory texts on larger screens.

plurals
  1. POHTTP request is not providing a result
    text
    copied!<p>Please help me to find a solution:</p> <p>If I call the URL (below) the server provide me a something like this:</p> <pre><code>"Name", "Date" "Peter", "01.01.2013" "Paul", "12.12.2012" </code></pre> <p>So the server provide me an SQL table as text. I tried to request this and convert it in a string. But when I run the app, the string is empty. </p> <p>Did I encode the URL right?<br> Did I manage the request right?</p> <p>Here is the URL:</p> <pre><code>http://IP/query.html?sql="select * from ADAnreden" </code></pre> <p>Here is the URL, which is posted by the Log.d:</p> <pre><code>http://IP/query.html?sql=%22select+*+from+ADAnreden%22 </code></pre> <p>Here is my code:</p> <pre><code>import java.io.BufferedInputStream; import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; import android.util.Log; public class Reader { private String result = "leer"; String strUrl = "getURL: fehlgeschlagen"; private HttpURLConnection urlConnection; public String getStringFromServer(){ String ip = "XYZ"; try { String query = URLEncoder.encode("\"select * from ADAnreden\"", "utf-8"); strUrl = "http://"+ip+"/query.html?sql=" + query; } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } Log.d(PACKAGE_NAME, "After getURL"+strUrl); Thread thread = new Thread() { @Override public void run() { try { URL url = new URL(strUrl); urlConnection = (HttpURLConnection) url.openConnection(); InputStream in = new BufferedInputStream(urlConnection.getInputStream()); result = convertStreamToString(in); } catch (Exception e) { e.printStackTrace(); } finally { urlConnection.disconnect(); } } }; thread.start(); return result; } static String convertStreamToString(java.io.InputStream is) { java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A"); return s.hasNext() ? s.next() : ""; } } </code></pre> <p>EDIT:</p> <p>Here is a sample request with the browser (in this case are only rows, so there are no , )</p> <p><img src="https://i.stack.imgur.com/jlN2z.jpg" alt="enter image description here"></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload