簡體   English   中英

http post方法問題

[英]http post method problem

在我的應用程序中,我使用outpost方法將數據發送到.net.Now中的Web服務。當我發送帶有空格或特殊字符的字符串時,它帶有例如測試字符串的字符串將顯示為test + string。

我正在使用帶有nameValuePair的httpDefaultClient來發送數據...我使用了UrlEncode函數來編碼我的字符串,但結果仍然相同......請幫幫我...

這是我的代碼

//web service call
                HttpClient client=new DefaultHttpClient();
                HttpPost request = new HttpPost();
                request.setURI(new URI(url2));

                List<NameValuePair> nameValuePairs=new ArrayList<NameValuePair>();
                //  nameValuePairs.add(new BasicNameValuePair("CreateHotSpots", value))
                nameValuePairs.add(new BasicNameValuePair("sKey",""+globalClass.getUser_key()));
                nameValuePairs.add(new BasicNameValuePair("sLAKE",encodedlakename));
                if(!(DragAndDropPinActivity.point.isEmpty())){
                    nameValuePairs.add(new BasicNameValuePair("sLAT",""+DragAndDropPinActivity.point.get(0)));
                    nameValuePairs.add(new BasicNameValuePair("sLon",""+DragAndDropPinActivity.point.get(1)));

                }
                else
                {
                    url2=url2.concat("&sLAT="+""+myLatitude);
                    url2=url2.concat("&sLon="+""+myLongitude);

                }

                nameValuePairs.add(new BasicNameValuePair("sDesc",encodedDesc));
                nameValuePairs.add(new BasicNameValuePair("sSpeciesofFish",encodedFishSpecies));
                nameValuePairs.add(new BasicNameValuePair("sBaitUsed",encodedbUsed));
                nameValuePairs.add(new BasicNameValuePair("sWeatherInformation",encodedwInfo));
                nameValuePairs.add(new BasicNameValuePair("season",encodedlseason));
                nameValuePairs.add(new BasicNameValuePair("sDesc",""+encodedDesc));
                if(share)
                {
                    nameValuePairs.add(new BasicNameValuePair("sShareInfo","true"));
                }
                else
                {
                    nameValuePairs.add(new BasicNameValuePair("sShareInfo","false"));
                }

                Log.e("name value pairs",""+nameValuePairs.toString());
                UrlEncodedFormEntity entity_st=new UrlEncodedFormEntity(nameValuePairs,"UTF-8");
                request.setEntity(entity_st);

                HttpResponse response = client.execute(request);
                HttpEntity resEntity = response.getEntity();  
                if (resEntity != null) { 

                    Responce=EntityUtils.toString(resEntity);
                    Log.i("responce ======",""+Responce);

                }

            }
            catch (Exception e) {
                e.printStackTrace();
                String message=e.getMessage();
                Log.e("meaasge with erroe",message);
            }

            return Responce;
        }

第1步

您已在中指定了“UTF-8”編碼

UrlEncodedFormEntity entity_st=new UrlEncodedFormEntity(nameValuePairs,"UTF-8"); 

嘗試將其更改為

UrlEncodedFormEntity entity_st=new UrlEncodedFormEntity(nameValuePairs); 

第2步

我注意到您添加到請求中的字符串稱為encodeXXXX

這是否意味着您在將它們添加到ValuePairs之前對它們進行編碼?

如果是這樣,請停止執行此操作並將其保留為普通字符串。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM