인증이 필요하고 운이 필요없는 REST 소스를 읽는 방법을 알아 내려고하고 있습니다. 나는 다음과 같이 작업을 잘 사용하여 C 번호를 가지고 :Java를 사용하여 REST 서비스에서 읽기
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(filename);
request.Accept = "application/xml";
request.ContentType = "application/xml";
request.KeepAlive = true;
// this part is not used until after a request is refused, but we add it anyways
CredentialCache myCache = new CredentialCache();
myCache.Add(new Uri(filename), "Basic", new NetworkCredential(username, password));
request.Credentials = myCache;
// this is how we put the uname/pw in the first request
string cre = String.Format("{0}:{1}", username, password);
byte[] bytes = Encoding.ASCII.GetBytes(cre);
string base64 = Convert.ToBase64String(bytes);
request.Headers.Add("Authorization", "Basic " + base64);
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
return response.GetResponseStream();
을하지만 자바 다음 작동하지 않습니다 :
URL url = new URL(dsInfo.getFilename());
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/xml");
conn.setRequestProperty("Content-Type", "application/xml");
BASE64Encoder encoder = new BASE64Encoder();
String encodedCredential = encoder.encode((dsInfo.getUsername() + ":" + dsInfo.getPassword()).getBytes());
conn.setRequestProperty("Authorization", "BASIC " + encodedCredential);
conn.connect();
InputStream responseBodyStream = conn.getInputStream();
를 스트림이 반환 :
Error downloading template
Packet: test_packet
Template: NorthwindXml
Error reading authentication header.
을 내가 잘못 무엇을 얻고있다 ?
감사 - 데이브
"작동하지 않음"은 무엇을 의미합니까? Wireshark를 사용하여 두 방법간에 네트워크의 차이점을 확인해 보셨습니까? –
OOPS - 죄송합니다. 위의 결과를 추가했습니다. –
서버가 RFC 2617을 올바르게 구현하고 있는지 확실합니까? 예를 들어 auth-scheme 토큰은 대소 문자를 구분합니다. –