【发布时间】:2014-04-18 09:39:25
【问题描述】:
我有一个接收 2 个(可选)参数的网络服务:
<resource path="getLogbookEvents">
<method name="POST">
<request>
<param name="startDate" style="query" type="xs:string"/>
<param name="endDate" style="query" type="xs:string"/>
</request>
<response>
<representation mediaType="application/json"/>
</response>
</method>
</resource>
我能够使用 HttpPost 连接并接收来自 Android 的答复,但网络服务从未接收到这两个参数中的任何一个。
HttpClient httpclient = new DefaultHttpClient();
HttpPost post = new HttpPost("http://... method URL ...");
//post.setHeader("media-type", "application/json; charset=UTF-8");
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("startDate", "2014-04-18T05:00:00"));
nameValuePairs.add(new BasicNameValuePair("endDate", "2014-04-18T06:00:00"));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(nameValuePairs);
// entity.setContentEncoding(HTTP.UTF_8);
post.setEntity(entity);
// make POST request to the given URL
HttpResponse httpResponse = httpclient.execute(post);
// receive response as inputStream
inputStream = httpResponse.getEntity().getContent();
我尝试了 HttpParams、JSONObject 和 nameValuePairs,但没有任何效果。我只是一直收到响应,就好像我没有指定任何参数一样。关于为什么会发生这种情况或我可以尝试获得获胜组合的其他任何想法?
【问题讨论】:
-
在 startdate 和 enddate 字段结构中检查数据库..
-
startdate 和 enddate 结构绝对正确。如果我使用与 SoapUI 相同的值请求它,我会得到正确的数据。
-
但是为什么你在 webservice api 的 type="xs:string" 中输入字符串...你可以得到日期格式的开始和结束日期。
-
在 webservice api 中使用 type="xs:dateTime"
-
很遗憾,我实际上无法编辑网络服务。如果需要,我可以尝试让负责更改它的人,但是看到它期望一个字符串并且一个字符串作为参数发送,我没有收到值的问题不应该与没有指定为日期的值有关.
标签: java android web-services http-post