从 Java 客户端 -Eclipse 使用经过 Windows 身份验证的 WebService 时,出现错误
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:876)
at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1229)
at java.net.InetAddress.getAllByName0(InetAddress.java:1180)
at java.net.InetAddress.getAllByName(InetAddress.java:1110)
at java.net.InetAddress.getAllByName(InetAddress.java:1046)
这是我的代码,虽然不是很好。让我知道如何解决此错误。另外,如果有任何进一步的链接到我所在的位置,请提出建议。
import com.microsoft.webservices.OfficeServer.QueryService.*;
import java.net.InetAddress;
import java.net.URL;
import org.apache.axis.client.Stub;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.NTCredentials;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.params.AuthPolicy;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.CoreProtocolPNames;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.EntityUtils;
public class ppConsume3
{
public static void main(String[] arg)
{
DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.getAuthSchemes().register(AuthPolicy.NTLM, new NTLMSchemeFactory());
httpclient.getCredentialsProvider().setCredentials(new AuthScope(null, 80), new NTCredentials("userName", "password", "http://delnshar881501/_vti_bin/search.asmx?WSDL", "SAPIENT"));
HttpConnectionParams.setConnectionTimeout(httpclient.getParams(), 5000);
HttpHost target = new HttpHost("http://delnshar881501/_vti_bin/search.asmx?WSDL",80);
System.getProperties().setProperty("http.proxyUser ", "userName");
System.getProperties().setProperty("http.proxyPass word", "password");
// Make sure the same context is used to execute
// logically related requests
HttpContext localContext = new BasicHttpContext();
String content;
try
{
// Execute a cheap method first. This will trigger NTLM
// authentication
HttpGet httpget = new HttpGet();
httpget.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
httpclient.execute(target, httpget, localContext);
// Execute an expensive method next reusing the same context
HttpGet httppost = new HttpGet();
httpget.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
HttpResponse response2 = httpclient.execute(target, httppost, localContext);
HttpEntity entity2 = response2.getEntity();
content = EntityUtils.toString(entity2);
}
catch (Exception e)
{
e.printStackTrace();
content = "<html><body><p>"+e.getMessage()+"</p></body></html>";
return;
}
}
}