Je souhaite envoyer une donnée POST RAW de {"userid": "userid","pass":"1222"}
en tant que nom d'utilisateur et mot de passe. J'ai une mise en page consistant en un nom d'utilisateur et un mot de passe qui sera récupéré en tant que nom d'utilisateur et mot de passe. J'ai besoin d'aide pour essayer ce pour moderniserAndroid. Comment envoyer des données brutes en utilisant un retrofit ou de l'aide en utilisant asynctask
// Triggers when LOGIN Button clicked
public void checkLogin(View arg0) {
// Initialize AsyncLogin() class with userid and password
new REST().execute();
}
public class REST extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
// The Username & Password
final EditText usr = (EditText) findViewById(R.id.username);
userid = (String) usr.getText().toString();
final EditText pw = (EditText) findViewById(R.id.password);
password = (String) pw.getText().toString();
}
@Override
protected Void doInBackground(Void... params) {
HttpURLConnection urlConnection=null;
String json = null;
// -----------------------
try {
HttpResponse response;
JSONObject jsonObject = new JSONObject();
jsonObject.accumulate("username", usr);
jsonObject.accumulate("password", password);
json = jsonObject.toString();
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://mark.journeytech.com.ph/mobile_api/authentication.php");
httpPost.setEntity(new StringEntity(json, "UTF-8"));
httpPost.setHeader("Content-Type", "application/json");
httpPost.setHeader("Accept-Encoding", "application/json");
httpPost.setHeader("Accept-Language", "en-US");
response = httpClient.execute(httpPost);
String sresponse = response.getEntity().toString();
Log.w("QueingSystem", sresponse);
Log.w("QueingSystem", EntityUtils.toString(response.getEntity()));
}
catch (Exception e) {
Log.d("InputStream", e.getLocalizedMessage());
} finally {
// nothing to do here
}
return null;
}
@Override
protected void onPostExecute(Void result) {
Toast.makeText(getApplicationContext(), email + " "+ password, Toast.LENGTH_SHORT).show();
if (result != null) {
// do something
} else {
// error occured
}
}
vous plaît toute aide parce que je cherchais beaucoup et n'atteins rien
Cocher cette https://code.tutsplus.com/tutorials/sending-data-with-retrofit-2-http-client-for-android--cms-27845 –
utilisant Asyntask vous avez fait ou pas? –
Salut Sunil, cela peut être fait. Pls. voir https://stackoverflow.com/questions/45428585/postman-is-working-cannot-send-raw-data-on-android/45428742?noredirect=1#comment77819608_45428742 –