我目前正在使用 HttpGet(apache) 方法向 Web 服务发出请求。当我调用服务器时,它给了我这个错误:
“请求时间和服务器时间之间的差异太大” 然后我知道服务器需要在 GMT 中有请求,所以我相应地添加了一个标头(addHeader)来做同样的事情。但我仍然有同样的问题。
有什么想法/想法吗?
一些代码:
final String url = "ip address";
final HttpGet request = new HttpGet(url);
final ArrayList<NameValuePair> nameValues = new ArrayList<NameValuePair>();
nameValues.add(new BasicNameValuePair("Authorization", "XXXX"));
nameValues.add(new BasicNameValuePair("date", "Fri, 19 Aug 2011 22:39:13 GMT"));
for (final NameValuePair h : nameValues)
{
request.addHeader(h.getName(), h.getValue());
}
final HttpClient client = new DefaultHttpClient();
HttpResponse httpResponse;
try
{
httpResponse = client.execute(request);
responseCode = httpResponse.getStatusLine().getStatusCode();
message = httpResponse.getStatusLine().getReasonPhrase();
final HttpEntity entity = httpResponse.getEntity();
if (entity != null)
{
final InputStream instream = entity.getContent();
response = convertStreamToString(instream);
instream.close();
}
}
catch (final Exception e)
{
}