2016-04-05 20 views
0

WinHttpClients ve bir GET isteği kullanıldığında ntlm kimlik doğrulaması gerektiren bir hizmet için başarıyla kimlik doğrulaması yapabildim. Ancak bir POST yapmaya çalıştığımda her zaman bir 401 dönüş kodu alırım. Bunu daha önce hiç kimse başardı mı?Apache Http Bileşenleri'nden WinHttpClients Kullanma

import java.io.IOException; 
import java.io.UnsupportedEncodingException; 

import org.apache.http.HttpEntity; 
import org.apache.http.HttpHost; 
import org.apache.http.auth.AuthScope; 
import org.apache.http.auth.NTCredentials; 
import org.apache.http.client.ClientProtocolException; 
import org.apache.http.client.CredentialsProvider; 
import org.apache.http.client.methods.CloseableHttpResponse; 
import org.apache.http.client.methods.HttpGet; 
import org.apache.http.client.methods.HttpPost; 
import org.apache.http.client.protocol.HttpClientContext; 
import org.apache.http.entity.StringEntity; 
import org.apache.http.impl.client.BasicCredentialsProvider; 
import org.apache.http.impl.client.CloseableHttpClient; 
import org.apache.http.impl.client.WinHttpClients; 


public class WindowsAuthPOst { 

public static void main (String []args) throws Exception, IOException 
{ 
    org.apache.log4j.BasicConfigurator.configure(); 
    CloseableHttpClient httpclient = WinHttpClients.createDefault(); 

    HttpHost target = new HttpHost("SomeHost.domain", 443, "https"); 

    HttpClientContext context = HttpClientContext.create(); 
    HttpGet httpget = new HttpGet("/some/Service.svc"); 
    CloseableHttpResponse response1 = httpclient.execute(target, httpget, context); 
    try { 
     HttpEntity entity1 = response1.getEntity(); 
    } finally { 
     response1.close(); 
    } 

    // Execute an expensive method next reusing the same context (and connection) 
    HttpPost httppost = new HttpPost("/some/Service.svc"); 
    httppost.setHeader("SOAPAction", "Some Soap Action"); 
    httppost.setEntity(new StringEntity("Soap Payload")); 
    CloseableHttpResponse response2 = httpclient.execute(target, httppost, context); 
    try { 
     HttpEntity entity2 = response2.getEntity(); 
    } finally { 
     response2.close(); 
    } 
} 

}

cevap

0

onunla olup olmadığını kontrol edebilirsiniz. Değilse

if (!WinHttpClients.isWinAuthAvailable()) { 
     System.out.println("Integrated Win auth is not supported!!!"); 
    } 

, sizin sınıf yolunda jna.jar yok olabilir. Bu, jna'ya bağlıdır ve false'u sessizce not there, see source code ise yukarıdaki gibi döndürür.

+0

Bu, POST değil GET için çalıştığı için kullanılabilir – Radford7821

İlgili konular