我正在尝试调用Web服务 它从本地目录读取文件simpleio.txt.toHCP并将其写入HCP。然后转身将对象读回到文件simpleio.txt.fromHCP。 但我得到例外如下
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.http.HttpHost.getAddress()Ljava/net/InetAddress;
at org.apache.http.conn.routing.HttpRoute.normalize(HttpRoute.java:106)
at org.apache.http.conn.routing.HttpRoute.<init>(HttpRoute.java:74)
at org.apache.http.conn.routing.HttpRoute.<init>(HttpRoute.java:170)
at org.apache.http.impl.conn.DefaultHttpRoutePlanner.determineRoute(DefaultHttpRoutePlanner.java:116)
at org.apache.http.impl.client.DefaultRequestDirector.determineRoute(DefaultRequestDirector.java:762)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:381)
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:882)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
at com.hds.hcp.examples.SimpleIO.WriteToHCP(SimpleIO.java:117)
at com.hds.hcp.examples.SimpleIO.main(SimpleIO.java:218)
代码是
void WriteToHCP() throws Exception {
/*
* Setup the PUT request.
*/
HttpPut httpRequest = new HttpPut(sHCPURLFilePath);
FileInputStream dataFile = new FileInputStream(sBaseFileName + ".toHCP");
System.out.println(dataFile.available());
// Point the HttpRequest to the input stream.
httpRequest.setEntity(new InputStreamEntity(dataFile, -1));
// Set HTTP Authorization Header with HCP credentials.
httpRequest.setHeader(HCPUtils.HTTP_AUTH_HEADER, "HCP" + sEncodedUserName + ":" + sEncodedPassword);
System.out.println(HCPUtils.HTTP_AUTH_HEADER);
System.out.println(sHCPURLFilePath);
System.out.println(sEncodedUserName);
System.out.println("HCP " + sEncodedUserName + ":" + sEncodedPassword);
/*
* Now execute the PUT request.
*/
HttpResponse httpResponse = mHttpClient.execute(httpRequest);
上述行引起的例外情况并不知道原因。感谢任何帮助。