This week's book giveaway is in the Functional programming forum.
We're giving away four copies of A Functional Approach to Java: Augmenting Object-Oriented Java Code with Functional Principles and have Ben Weidig on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Peter Rooke
  • Himai Minh
Bartenders:
  • Piet Souris
  • Mikalai Zaikin

Sending a jason object via Post

 
Ranch Hand
Posts: 100
Android Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I nead to send a JSON object via POST object. Can anybody help me with a small example ?

Kind Regards,

 
Sheriff
Posts: 67706
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JSON, not "jason".

From where? The client? Server code?
 
Robert Darling
Ranch Hand
Posts: 100
Android Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for the typo.

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.

Many thanks for your help.

Kind Regards.

 
Robert Darling
Ranch Hand
Posts: 100
Android Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,



 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.)
 
Robert Darling
Ranch Hand
Posts: 100
Android Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when i say its not working, i mean i am gettting an invalid request. I have changed the code to the following


The variable a should contain a jason object containing the user information but it contains something like this


<TITLE>ERROR: The requested URL could not be retrieved</TITLE>



The server url is fine and in working condition. My android app can contact to the internet, so that's not fine. Sop where am i going wrong.

Kind Regards,

 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd start by examining what the server receives; obviously that's different from what it expects to receive.
 
Robert Darling
Ranch Hand
Posts: 100
Android Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The document given to me states that


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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you saying that the server is not under your control, so that you can't debug on it?
 
Robert Darling
Ranch Hand
Posts: 100
Android Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes the server is not under my control. The existing IPhone application is working fine and i am responsible for porting the application to Android.
 
Robert Darling
Ranch Hand
Posts: 100
Android Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
AppURL/users/getuserdetails?jason={"Email":"abc@gmaill.com","Password":"xyz"}

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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic