user1248568
user1248568

Reputation: 621

Creating correct HTTP POST data

Im new at android development and now I need to create and use POST request. According to this post I have tried to put my data:

            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(13);
            nameValuePairs.add(new BasicNameValuePair("SelectedCode", "25"));
            nameValuePairs.add(new BasicNameValuePair("Phone", "1234567"));
            nameValuePairs.add(new BasicNameValuePair("Text", "1234"));
            nameValuePairs.add(new BasicNameValuePair("IsTranslit", "false"));
            nameValuePairs.add(new BasicNameValuePair("IsShedule", "false"));
            nameValuePairs.add(new BasicNameValuePair("LastDate", ""));
            nameValuePairs.add(new BasicNameValuePair("LastDateHour", "00"));
            nameValuePairs.add(new BasicNameValuePair("LastDateMinuts", "00"));
            nameValuePairs.add(new BasicNameValuePair("DateSendBefore", ""));
            nameValuePairs.add(new BasicNameValuePair("DateSendBeforeHour", "00"));
            nameValuePairs.add(new BasicNameValuePair("DateSendBeforeMinuts", "00"));
            nameValuePairs.add(new BasicNameValuePair("CaptchaDeText", "h3Vcjwk2moLagspo7lnKpg%3D%3D"));
            nameValuePairs.add(new BasicNameValuePair("CaptchaInputText", "4myin2"));
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

but it doesnt work. Then I have tried to use this code (sorry for a long line)

            httppost.setEntity(new StringEntity("SelectedCode=25&Phone=1234567&Text=123&IsTranslit=false&IsShedule=false&LastDate=&LastDateHour=00&LastDateMinuts=00&DateSendBefore=&DateSendBeforeHour=00&DateSendBeforeMinuts=00&CaptchaDeText=h3Vcjwk2moLagspo7lnKpg%3D%3D&CaptchaInputText=4myin2"));

And it works. Can someone explain what is difference or what Im doing wrong?

UPDATED:

By doesnt work I mean that server does not recognize this post request as correct. It will happen if I add incorrect value in NameValuePair list for example. But from my side name and value in first piece of code and in the second are the same. It makes me wonder.

Upvotes: 1

Views: 158

Answers (1)

user1248568
user1248568

Reputation: 621

vmirionov's comment solved this issue. Changing h3Vcjwk2moLagspo7lnKpg%3D%3D to h3Vcjwk2moLagspo7lnKpg== made a trick.

Upvotes: 1

Related Questions