Ich versuche zu holen Daten von einem Server über diese URL www.example.com/directory/ aber es funktioniert nicht machen ... es kam, dass json mit diesem nach oben ist keine Aktion zum Server zu senden ... so alles, was ich möchte die uRL zu machen, ist dies way-- www.example.com/directory/index.php?action=searchFood & Geld = 50wie Parameter url in android json
Das ist mein JsonFetcher.java
public class JsonFetcher extends AsyncTask<Pair<String, String>, Integer, JSONObject> {
private JSONObject jsonObject;
public AsyncResponse delegate = null;
public interface AsyncResponse {
void processFinish(JSONObject output);
}
public JsonFetcher(AsyncResponse delegate) {
this.delegate = delegate;
}
@Override
protected void onPostExecute(JSONObject jsonObject) {
super.onPostExecute(jsonObject);
delegate.processFinish(jsonObject);
}
@Override
protected JSONObject doInBackground(final Pair<String, String>... params) {
int count = params.length;
URL url = null;
int responseCode = 0;
jsonObject = null;
try {
url = new URL("http://www.example.com/directory/");
} catch (MalformedURLException e) {
e.printStackTrace();
}
HttpURLConnection conn = null;
try {
conn = (HttpURLConnection) url.openConnection();
//conn.connect();
} catch (IOException e) {
e.printStackTrace();
}
try {
conn.setRequestMethod("POST");
conn.setDoInput(true);
conn.setDoOutput(true);
Uri.Builder builder = new Uri.Builder();
Date date = new Date();
String md5 = date.toString();
//Log.e("json lock",lock);
//Log.e("json key",md5);
for (int i = 0; i < count; i++) {
builder.appendQueryParameter(String.valueOf(params[i].first),String.valueOf(params[i].second));
}
String query = builder.build().getEncodedQuery();
OutputStream os = conn.getOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
writer.write(query);
writer.flush();
writer.close();
os.close();
} catch (ProtocolException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// read the response
try {
responseCode = conn.getResponseCode();
} catch (IOException e) {
e.printStackTrace();
}
if (responseCode == HttpsURLConnection.HTTP_OK) {
InputStream in = null;
try {
in = new BufferedInputStream(conn.getInputStream());
} catch (IOException e) {
e.printStackTrace();
} finally {
//conn.disconnect();
}
BufferedReader r = new BufferedReader(new InputStreamReader(in));
StringBuilder total = new StringBuilder();
String line;
try {
while ((line = r.readLine()) != null) {
total.append(line);
}
} catch (IOException e) {
e.printStackTrace();
}
Log.e("json", total.toString());
try {
jsonObject = new JSONObject(total.toString());
} catch (JSONException e) {
e.printStackTrace();
}
}
return jsonObject;
}
}
Gibt es eine Möglichkeit, auf diese Weise zu schreiben
url = new URL("http://www.example/directory/index.php?action= PairActionName & PairMoney");
hier PairActionName und PairMoney wird von MainActivity werden empfangen
haben dies auf einem REST-Client versucht? Was bekommen Sie auf REST-Client? –
Herr, wenn ich versuche, auf xampp es Ergebnis zu verwenden und Anzeige in Listview nur mit dieser URL ("http://192.168.1.110/directory/") –
nach dem Hochladen auf Server ich bekomme Problem –