这就是我的网址:
在java(http post request)中发布后,它将被重定向到此URI:
https://kuma.ruto/v1/0auth/grant?state=some&code=的 YrnYdnHdY
如何获取重定向URI并获取代码值?
以下是代码段:
String data =“email = p@f.com& password = Airtel @ 2017”; 网址url =新网址(“https://login.something.com/v1/oauth/authorize?response_type=code&state=none&email=p@f.com&client_id=jkhsdhaskfhdash&password=Airtel@2017&redirect_uri=https://login.something.com&code=none”);
// Support for constraint-based layout (auto layout) // If nonzero, this is used when determining -intrinsicContentSize for multiline labels @property(nonatomic) CGFloat preferredMaxLayoutWidth NS_AVAILABLE_IOS(6_0);
答案 0 :(得分:0)
您可以查看以下示例:
HttpClient client = new DefaultHttpClient();
HttpGet method = new HttpGet(joinUrl);
HttpContext context = new BasicHttpContext();
HttpResponse httpResponse = client.execute(method, context);
if (httpResponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK)
log.debug("HTTP GET {} return {}", joinUrl, httpResponse.getStatusLine().getStatusCode());
HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(
ExecutionContext.HTTP_REQUEST);
if (!currentReq.getURI().getPath().equals("/client/BigBlueButton.html")) {
log.warn("It was redirected to {} instead of /client/BigBlueButton.html: the server was branded" +
" and the HTML name was changed, or it's an error. However, it will continue processing", currentReq.getURI().getPath());
}
HttpHost currentHost = (HttpHost) context.getAttribute(
ExecutionContext.HTTP_TARGET_HOST);
String enterUrl = currentHost.toURI() + "/bigbluebutton/api/enter";
答案 1 :(得分:0)
这个例子怎么样?:
// loop until no more redirections are
for (;;) {
if (Thread.currentThread().isInterrupted()) {
return null;
}
if(proxy != null) {
ucn = downloadURL.openConnection(proxy);
} else {
ucn = downloadURL.openConnection();
}
HttpURLConnection hucn = doConfigureURLConnection(ucn);
if(Thread.currentThread().isInterrupted())
return null;
ucn.connect();
int rc = hucn.getResponseCode();
boolean isRedirect =
rc == HttpURLConnection.HTTP_MOVED_TEMP ||
rc == HttpURLConnection.HTTP_MOVED_PERM;
if (!isRedirect) {
break;
}
String addr = hucn.getHeaderField(HTTP_REDIRECT_LOCATION);
URL newURL = new URL(addr);
if (!downloadURL.getProtocol().equalsIgnoreCase(newURL.getProtocol())) {
throw new ResourceRedirectException(newURL);
}
downloadURL = newURL;
}