1
即時通訊新的android開發,現在我需要創建和使用POST請求。根據這一post 我試圖把我的數據:創建正確的HTTP POST數據
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));
但它不工作。然後,我曾嘗試使用此代碼(對不起,長線)
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"));
而且它的工作原理。 有人可以解釋什麼是不同或我做錯了什麼?
更新:
通過不工作我指的是服務器無法識別該POST請求是正確的。例如,如果我在NameValuePair列表中添加了不正確的值,就會發生這種情況。但從我的名字和價值的第一塊代碼和第二個是相同的。這讓我想知道。
不工作不是錯誤。發生了什麼,發送了什麼,服務器收到了什麼? – CodeCaster 2013-03-20 17:43:37
如果我記得好,UrlEncodedFormEntity編碼每個參數,但你的'h3Vcjwk2moLagspo7lnKpg%3D%3D'參數已被編碼。這可能是一個問題 – 2013-03-20 17:46:48
嗯,是的,你是對的 – user1248568 2013-03-20 20:07:27