2015-11-03 62 views
0

我有一個簡單的網站,我在玩,需要輸入電子郵件和密碼才能登錄。這一切在PC瀏覽器和蘋果手機/平板電腦上都可以正常工作。C#MVC Android URL編碼參數

但是,droid設備無法登錄。我通過我的電腦路由了我的測試電話,並使用提琴手查看http流量,並且Android正在編碼電子郵件地址,因此而不是[email protected],我看到foo %40here.com,所以我的服務器端驗證失敗,因爲這不是一個有效的電子郵件地址。

檢測此問題的簡單方法是在驗證它之前簡單查看電子郵件字符串,然後查找%40符號。但是如果android默認默認使用urlencode,那麼這可能會給我帶來更多問題,並且不得不檢查字符串,並猜測%是否是某種url編碼的一部分,否則真正的百分比將成爲問題。

那麼是否有一個屬性或過濾器我可以適用於我的方法,以便該框架將根據需要unncode,或者我需要處理這種情況的個案基礎?

+0

這很奇怪,我想了解更多信息。你能發佈發送屬性的代碼嗎?另一方面,我想你使用GET發送信息,爲什麼不使用POST?執行登錄時推薦使用POST。 – thelawnmowerman

+0

只需使用其中一種c#解碼工具,你就會好起來的。 –

+0

@thelawnmowerman表單被設置爲發佈,到目前爲止它只是一個樣板html表單。它只是'這樣做 – Matt

回答

0

嘗試通過增加("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");線在您的要求在控制器上發送請求 這樣request.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");

本身的例子

HttpClient httpClient = new DefaultHttpClient(); 
     HttpPost request = new HttpPost(Constants.mWebURL+Constants.mSendBloodReq); 
     request.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8"); 
     // adding paramaters 
     List<NameValuePair> postParameters = new ArrayList<NameValuePair>(); 
     postParameters.add(new BasicNameValuePair("user_id",params[0])); 
     postParameters.add(new BasicNameValuePair("password",params[1])); 
        UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParameters,"UTF-8"); 
     request.setEntity(formEntity); 
     HttpResponse httpresponse = httpClient.execute(request); 
     //getting response 
     response = EntityUtils.toString(httpresponse.getEntity()); 
0

我的方法之前沒有用[HttpPost]屬性裝飾。這似乎已經修好了我