我目前正在使用 HttpGet(apache) 方法向 Web 服务发出请求。 当我调用服务器时,它给了我这个错误:
“请求时间与服务器时间相差太大” 然后我知道服务器需要在 GMT 中接收请求,因此我相应地添加了一个 header (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)
{
}
最佳答案
我能够解决这个问题。
当我使用 CST 通话时,我发现服务器已设置为 GMT。
关于java - 如何向 httpGet 添加日期 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7127799/