I nead to send the JSON object fro the client. I have made a JSON object containing the data that needs to be sent. My client is a android phone and needs to write data to a Web Service (already implemented and working) over a Request object and then read the response. How do you send a JSON object over a request.
Some sample code will be good, as i am new to JSON.
I nead to send the login information in the format :{"Email":"abc@xyz.co","Password":"123456"} and then read the user login information back via JSON. Really stuck on this. This is what i am trying. This code is from my android client.
The server reads the data from a variable called jsonRequest. That's why the line tagged with 1 will sets the header variable and its value. responseStr in the last line should hold the value of the user information from the server in the form of a JSON object. I can parse the object but its not working. Where am i going wrong. Really stuck in this, so any help would be appreciated.
Kind Regards,
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35253
7
posted
0
What does "it's not working" mean? Is the HTTP request being sent as you want it to be sent? Is the server receiving all data correctly? If so, does it return all data as it should? And finally, what is the response received on the device?
Also, if you want to send a POST, why are you using HttpGet?
(As an aside, and as I told you before in the other thread where you asked about this, there's nothing at all Android-specific about this.)
Request:{"Email":"abc@xyz.com","Password":"123456"}
The above structure is sent to Server in a variable named “json”
If the request is successful a JSON Object is returned with the user details. If i provide the actual url for the web service could you try and send a request and see what you recieve at your end.
Kind Regards,
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35253
7
posted
0
Are you saying that the server is not under your control, so that you can't debug on it?
I posted this address in firefox and it printed {"error","-1"}. that was expected. So the web server is working fine. So whats then wrong with this code
All really that i have to do is send a variable called json with the jason object in it. I think things should be much clearer .
Kind Regards.
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35253
7
posted
0
There are several differences between using the URL, and using the code you posted:
1) a browser URL causes a GET, not a POST
2) the URL uses "jason" as name of the parameter, whereas the code uses "json" as header name
3) HTTP headers and HTTP parameters are not at all the same thing - if the server expects one then you can't substitute the other
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.