in Education by
I want to send the following JSON text {"Email":"[email protected]","Password":"123456"} to a web service and read the response. I know to how to read JSON. The problem is that the above JSON object must be sent in a variable name jason. How can I do this from android? What are the steps such as creating request object, setting content headers, etc. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Sending a json object from Android is easy if you use Apache HTTP Client. Here's a code sample on how to do it. You should create a new thread for network activities so as not to lock up the UI thread. protected void sendJson(final String email, final String pwd) { Thread t = new Thread() { public void run() { Looper.prepare(); //For Preparing Message Pool for the child Thread HttpClient client = new DefaultHttpClient(); HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000); //Timeout Limit HttpResponse response; JSONObject json = new JSONObject(); try { HttpPost post = new HttpPost(URL); json.put("email", email); json.put("password", pwd); StringEntity se = new StringEntity( json.toString()); se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); post.setEntity(se); response = client.execute(post); /*Checking response */ if(response!=null){ InputStream in = response.getEntity().getContent(); //Get the data in the entity } } catch(Exception e) { e.printStackTrace(); createDialog("Error", "Cannot Estabilish Connection"); } Looper.loop(); //Loop in the message queue } }; t.start(); } You could also use Google Gson to send and retrieve JSON.

Related questions

0 votes
    I am working on my first Android Application. What I am trying to do is a POST request to a REST ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    I am using the following function to load a PlayList of Songs from 'PlayListJSON.aspx' but somethings seems ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    I am working in an graphql application where I have to send custom error object / message in json ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    What I'm trying to do here is get the headers of a given URL so I can determine the MIME type. ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    I have been looking for a long time but cannot find anything regarding this little quest of mine. I ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 16, 2022 in Education by JackTerrance
0 votes
    object looks like as below { "id":1, "image":"path/to/image", "employee_data":, } again ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 13, 2022 in Education by JackTerrance
0 votes
    object looks like as below { "id":1, "image":"path/to/image", "employee_data":, } again ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    What I'm trying to do here is iterate inside a Json Object obtained from an API Call in order to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 13, 2022 in Education by JackTerrance
0 votes
    Which of these class must be used to send a datagram packets over a connection? (a) InetAdress (b) ... programming questions and answers pdf, java interview questions for beginners...
asked Oct 25, 2021 in Education by JackTerrance
0 votes
    I'm certain I'm missing something obvious, but the gist of the problem is I'm receiving a PNG ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 18, 2022 in Education by JackTerrance
0 votes
    I have a JSON File with database environment configuration called env-config.json like this: { "LATEST":{ ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
0 votes
    How to convert JSON string into an object?...
asked Jan 11, 2021 in Technology by JackTerrance
0 votes
    How can you send data using a Worker object? (a) postMessage() (b) sendMessage() (c) Message() ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 22, 2021 in Education by JackTerrance
0 votes
    I'm looking at making an custom Android object Serializable. Should be simple I just cannot find a easy ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Aug 1, 2022 in Education by JackTerrance
...