On 28 August 2011 02:19, MK Z <[email protected]> wrote:
> Hi,
> Ive been trying for days now to get form data send to GAE datastore.
> Ive looked through stackoverflow and some other sites for example..
> basically this is what i done:
>
> android side:
> public class myapp extends Activity
> {
>    /** Called when the activity is first created. */
>    @Override
>    public void onCreate(Bundle savedInstanceState)
>    {
>         super.onCreate(savedInstanceState);
>         TextView tv = new TextView(this);
>        tv.setText("Hello, Android");
>         HttpClient client;
>         String response="";
>
>         try {
>             client = new DefaultHttpClient();
>             DefaultHttpClient hc=new DefaultHttpClient();
>             ResponseHandler <String> res=new BasicResponseHandler();
>             HttpPost postMethod=new HttpPost("http://
> myapp.appspot.com/savename");
>             List<NameValuePair> nameValuePairs = new
> ArrayList<NameValuePair>();
>             nameValuePairs.add(new BasicNameValuePair("name", "John
> Doe"));
>             postMethod.setEntity(new
> UrlEncodedFormEntity(nameValuePairs));
>             response=hc.execute(postMethod,res);
>             Log.v("resp", response);
>         } catch (Exception e) {
>             e.printStackTrace();
>         }
>
>         setContentView(tv);
>     }
>
>    }
>
> on GAE i have this servlet:
>
>
> public void doPost(HttpServletRequest req, HttpServletResponse resp)
>                        throws IOException {
>
>
>                Date date = new Date();
>                String name =req.getParameter("name");
>
>                        dem.addName(Name,date);
>
> }
>
>
>
> When I run the android app and check GAE datastore, the value i set on
> android client does not get stored into the database... can someone
> help?

MK Z,

Is your problem that it does not get posted, does not get received
received or does not get stored?
You have to verify, what does your HttpClient actualy post if it posts
at all, and what your servlet receives.

Use Wireshark (or other packet snooping software) on the client side
to see your request verbatim.
On the server side dump into some debug log/console all headers and
body of your POST.

The first things to verify would be presence of following 2 very
important http headers in your POST request:

Content-Type: application/x-www-form-urlencoded
Content-Length: <the_length_of_your_data_in_bytes>


If you have those, then keep debugging. If not, add them manually to
your HttpPost object on the client side.

As you see, you will have to build the body, add it to your post and
count the bytes.

HTH

-- 
Daniel Drozdzewski

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to