Thursday, September 22, 2011

[android-developers] Re: Always getting GET on the server eventhough POST was sent

Well, for a starter your #addHeader("Content-Type", "application/
json") doesn't really make sense since you're in fact sending
application/x-www-form-urlencoded when you're pushing an
UrlEncodedFormEntity to the server - otherwise it looks about right.

Are you getting a HTTP 3xx redirect - that could .. result in a GET..
I guess? You can disable processing of redirects with
HttpClientParams.setRedirecting(.., false) and see if it breaks in new
and interesting ways then.

On 22 Sep, 16:44, Joshua Partogi <joshua.part...@gmail.com> wrote:
> Hi there,
>
> I am trying to send data using POST method from my android apps. However in
> the server it is always recognized as GET. I am using Rails apps as the web
> service. Here is the snippet of my Android code:
>
>  URI uri = new URI(hostName);
>
> HttpPost httpRequest = new HttpPost(uri);
>
>  httpRequest.addHeader("Accept", "application/json");
>
>  httpRequest.addHeader("Content-Type", "application/json");
>
>  List<NameValuePair> pairs = new ArrayList<NameValuePair>();
>
>  pairs.add(new BasicNameValuePair("key1", "value1"));
>
>  httpRequest.setEntity(new UrlEncodedFormEntity(pairs));
>
> HttpClient httpClient = new DefaultHttpClient();
>
> HttpResponse httpResponse = httpClient.execute(httpRequest);
>
> Have I done anything wrong? Thanks for your help.
>
> Kind regards,
> Joshua.
>
> --
> @jpartogi

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

No comments:

Post a Comment