我无法从Android-API中获取HttpParams内容.
我只是不想用我的Postrequest发送一些简单的参数.除参数外,一切正常.将参数设置为postrequest的代码:
HttpParams params = new BasicHttpParams();
params.setParameter("password", "secret");
params.setParameter("name", "testuser");
postRequest.setParams(params);
Run Code Online (Sandbox Code Playgroud)
似乎这段代码根本没有添加任何参数,因为服务器总是回答,我的请求缺少"名称"参数.
实际按预期工作的一个例子:
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("name", "testuser"));
postParameters.add(new BasicNameValuePair("password", "secret"));
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParameters);
postRequest.setEntity(formEntity);
Run Code Online (Sandbox Code Playgroud)
但我想使用第一个例子的版本,因为它更容易阅读和理解.
任何暗示都非常感谢!
我正在尝试使用SimpleDateFormat在unix时间戳和自定义格式之间进行转换,反之亦然.为了测试这个反之亦然转换我编写了以下测试用例:
public class Testception extends TestCase {
public void testTheTestOrTestception() throws ParseException {
Date datum = new Date(649555200000L);
SimpleDateFormat dfm = new SimpleDateFormat("yyyy-MM-dd");
TimeZone tZ = TimeZone.getTimeZone("Europe/Berlin");
dfm.setTimeZone(tZ);
String aDifferentFormat = dfm.format(datum);
assertEquals("1990-08-02", aDifferentFormat);
Date datum2 = dfm.parse(aDifferentFormat);
assertEquals(649555200000L, datum2.getTime());
}
}
Run Code Online (Sandbox Code Playgroud)
我开始使用unixtimestamp(649555200000),以我的自定义格式("1990-08-02")转换它,这很好用.但不幸的是,第二个断言失败,而不是预期的649555200000L,结果是649548000000L
提前致谢.
干杯L0rdAli3n