我有一个需要电子邮件和密码的登录名。
如果我从邮递员休息客户那里得到它:
www.site.com/login.json?session[email]=bob@gmail.com&session[password]=password
服务器(Rails)会很好地读取它,如下所示:
{"session"=>{"email"=>"bob@gmail.com", "password"=>"password"}, "action"=>"create", "controller"=>"sessions", "format"=>"json"}
但是,如果我使用来自 android 的 HTTPGet 发送相同的内容,如下所示:
HttpClient httpclient = new DefaultHttpClient();
//get the parameters
String email = params[0];
String password = params[1];
String url = "http://www.site.com/login.json?session[email]=" + email + "?session[password]=" + password;
HttpGet httpget = new HttpGet(url);
httpget.setHeader("Accept", "application/json");
httpget.setHeader("Content-type", "application/json");
response = httpclient.execute(httpget);
服务器无法识别参数,我最终得到一个空的 json 对象,如下所示:
{"session"=>{}, "action"=>"create", "controller"=>"sessions", "format"=>"json"}
任何人都知道如何在 android 中的这个 HTTPGet 调用中形成参数,以便像在其余客户端调用中一样工作?谢谢!