선생님, httppost로 로그인 모듈을 구현할 것입니다. 메커니즘은 내가 URL을 http://api.apc.com/u/authorize와 httppost로의 HTTP PARAMATERS를 넣고 실행 때, api.apc.com/auth/authorized?u=3cdndskjsijdso9808이HTTP Post Exceute 후 Java GET 리디렉션 된 URL
을 반환 할 것입니다U = 3cdndskjsijdso9808 성공적으로 로그인 한 후 사용자 토큰입니다 .
수천 개의 헤더 필드가 출력되지만 안드로이드 장치에서는 헤더 "위치"가 발견되지 않고 이지만 구현 및 테스트에서는 PC 브라우저를 찾을 수 있습니다.
http 응답 헤더의 속성 및 값을 가져 오는 다른 방법이 있습니까? 자동 리디렉션을 따르지 않는 있도록 DefaultHttpClient를 구성 할 때
HttpClient client = new DefaultHttpClient();
String url = "https://api.hkgalden.com/u/authorize";
HttpPost httpPost = new HttpPost(url);
httpPost.addHeader("X-GALAPI-KEY", "ecb954a155e6bbd9fe3fe166940feb102c80ae90");
httpPost.setHeader("Cache-Control", "no-cache");
httpPost.setHeader("Pragma", "no-cache");
Log.v("HTTP", "Header Added");
try {
//add HTTP parameters
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("email", email));
nameValuePairs.add(new BasicNameValuePair("appid", "27"));
nameValuePairs.add(new BasicNameValuePair("password", password));
nameValuePairs.add(new BasicNameValuePair("deviceid", "mobile_id"));
nameValuePairs.add(new BasicNameValuePair("dname", "Galden+ mobile device"));
Log.v("HTTP", "Parameters Added");
//send HTTP request
//httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
/*
String paramString = URLEncodedUtils.format(nameValuePairs, "utf-8");
url += ("?" + paramString);
*/
//execute HTTP response
/*
HttpGet get = new HttpGet (url);
get.addHeader("X-GALAPI-KEY", "ecb954a155e6bbd9fe3fe166940feb102c80ae90");
get.setHeader("Cache-Control", "no-cache");
get.setHeader("Pragma", "no-cache");*/
final HttpParams httpParams = new BasicHttpParams();
HttpClientParams.setRedirecting(httpParams, false);
HttpResponse httpResponse = client.execute(httpPost);
//HttpResponse httpResponse = client.execute(get);
Log.v("HTTP", "Request Executed");
//if execute success
int respondCode = httpResponse.getStatusLine().getStatusCode();
Log.d("HTTP Status Code" , String.valueOf(respondCode));
if (respondCode== 404 || respondCode == 200){
SystemUtils.toast(getApplication(), "Login Success!");
// String temp = httpResponse.getStatusLine().toString();
// String temp = httpResponse.getLastHeader("Location").getValue();
// String temp = httpResponse.getHeaders();
// Log.v("URL", temp);
Header[] headers = httpResponse.getAllHeaders();
for (Header header : headers) {
Log.v(header.getName(), header.getValue());
}
for(Header header : httpResponse.getHeaders("Location")) {
System.out.println("Location from connect:" + header.getValue());
SystemUtils.toast(getApplication(), "URL : " + header.getValue());
}
String data = slurp(httpResponse.getEntity().getContent() , 1024);
Log.v("url", data);
}
else SystemUtils.toast(getApplication(), "Login Fail! Error code: " + Integer.toString(httpResponse.getStatusLine().getStatusCode()));
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
왜 메모리 자체가 이러한 리디렉션 URL을 캐시하고 헤더 위치를 숨길 수 있습니까? –
여전히 매개 변수가있는 리다이렉트 URL이 없기 때문에 실패합니다. 이제 어떻게해야합니까? –
원래 게시물에 업데이트 된 코드를 추가하십시오. –