2015-11-03 59 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]属性装饰。这似乎已经修好了我