本文整理汇总了Java中com.badlogic.gdx.Net.HttpRequest.setUrl方法的典型用法代码示例。如果您正苦于以下问题:Java HttpRequest.setUrl方法的具体用法?Java HttpRequest.setUrl怎么用?Java HttpRequest.setUrl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.badlogic.gdx.Net.HttpRequest
的用法示例。
在下文中一共展示了HttpRequest.setUrl方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import com.badlogic.gdx.Net.HttpRequest; //导入方法依赖的package包/类
@Override
public void create () {
HttpRequest request = new HttpRequest(HttpMethods.GET);
request.setUrl("http://libgdx.badlogicgames.com/nightlies/dist/AUTHORS");
Gdx.net.sendHttpRequest(request, new HttpResponseListener() {
@Override
public void handleHttpResponse (HttpResponse httpResponse) {
Gdx.app.log("HttpRequestExample", "response: " + httpResponse.getResultAsString());
}
@Override
public void failed (Throwable t) {
Gdx.app.error("HttpRequestExample", "something went wrong", t);
}
@Override
public void cancelled () {
Gdx.app.log("HttpRequestExample", "cancelled");
}
});
}
示例2: sendRequest
import com.badlogic.gdx.Net.HttpRequest; //导入方法依赖的package包/类
protected void sendRequest(String method, Map<String, String> params, final NetworkListener listener){
HttpRequest httpPost = new HttpRequest(HttpMethods.POST);
httpPost.setUrl(website + method + ".php");
httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
httpPost.setContent(HttpParametersUtils.convertHttpParameters(params));
Gdx.net.sendHttpRequest (httpPost, new HttpResponseListener() {
public void handleHttpResponse(Net.HttpResponse httpResponse) {
String responce = new String(httpResponse.getResult());
String dat = decrypt(responce, ENC_KEY);
listener.finished(dat);
listener.length(dat.getBytes().length);
}
public void failed(Throwable t) {
listener.failed(t);
}
public void cancelled(){
}
});
}
示例3: urlCheck
import com.badlogic.gdx.Net.HttpRequest; //导入方法依赖的package包/类
private void urlCheck(final String url, final LinkListener listener) {
HttpRequest request = new HttpRequest(HttpMethods.GET);
request.setUrl(url);
request.setTimeOut(TIMEOUT_MS);
Gdx.net.sendHttpRequest(request, new HttpResponseListener() {
@Override
public void handleHttpResponse(HttpResponse httpResponse) {
if (httpResponse.getStatus().getStatusCode() == HttpStatus.SC_OK) {
listener.ok(url);
} else {
listener.ko(url);
}
}
@Override
public void failed(Throwable t) {
listener.ko(url);
}
@Override
public void cancelled() {
listener.ko(url);
}
});
}
示例4: create
import com.badlogic.gdx.Net.HttpRequest; //导入方法依赖的package包/类
@Override
public void create () {
batch = new SpriteBatch();
HttpRequest request = new HttpRequest(HttpMethods.GET);
request.setUrl("https://www.google.at/images/srpr/logo11w.png");
Gdx.net.sendHttpRequest(request, new HttpResponseListener() {
@Override
public void handleHttpResponse (HttpResponse httpResponse) {
final byte[] bytes = httpResponse.getResult();
Gdx.app.postRunnable(new Runnable() {
@Override
public void run () {
Pixmap pixmap = new Pixmap(bytes, 0, bytes.length);
texture = new Texture(new PixmapTextureData(pixmap, pixmap.getFormat(), false, false, true));
}
});
}
@Override
public void failed (Throwable t) {
t.printStackTrace();
Gdx.app.log("EmptyDownloadTest", "Failed", t);
}
@Override
public void cancelled () {
Gdx.app.log("EmptyDownloadTest", "Cancelled");
}
});
}
示例5: getTAPData
import com.badlogic.gdx.Net.HttpRequest; //导入方法依赖的package包/类
private String[][] getTAPData(String url, boolean hip, final String format, final GaiaDataListener listener) {
HttpRequest request = new HttpRequest(HttpMethods.GET);
request.setUrl(url);
request.setTimeOut(5000);
Gdx.net.sendHttpRequest(request, new HttpResponseListener() {
@Override
public void handleHttpResponse(HttpResponse httpResponse) {
if (httpResponse.getStatus().getStatusCode() == HttpStatus.SC_OK) {
// Ok
listener.ok(isToArray(httpResponse.getResultAsStream(), format), hip);
} else {
// Ko with code
listener.ko(httpResponse.getStatus().toString());
}
}
@Override
public void failed(Throwable t) {
// Failed
listener.ko();
}
@Override
public void cancelled() {
// Cancelled
listener.ko();
}
});
return null;
}
示例6: loadClientId
import com.badlogic.gdx.Net.HttpRequest; //导入方法依赖的package包/类
/**
* Loads the client identifier from preferences. If it does not exists,
* obtains one from bugr.
*/
protected void loadClientId() {
String clientId = controller.getPreferences().getString(
Preferences.CLIENT_ID);
if ("".equals(clientId) || clientId == null) {
HttpRequest request = new HttpRequest("POST");
request.setUrl(bugrURL + ACTIVATE_PATH);
// Obtain an unique id
Gdx.net.sendHttpRequest(request, new HttpResponseListener() {
@Override
public void handleHttpResponse(HttpResponse httpResponse) {
if (httpResponse.getStatus().getStatusCode() == 200) {
cid = httpResponse.getResultAsString();
controller.getPreferences().putString(
Preferences.CLIENT_ID, cid);
// Start session with recently acquired cid
startSession();
} else {
Gdx.app.error("Tracker",
"Impossible to activate this installation. Server said:\n"
+ httpResponse.getResultAsString());
}
}
@Override
public void failed(Throwable throwable) {
Gdx.app.error("Tracker",
"Impossible to activate this installation.",
throwable);
}
@Override
public void cancelled() {
}
});
} else {
this.cid = clientId;
}
}
示例7: sendHttpGetRequest
import com.badlogic.gdx.Net.HttpRequest; //导入方法依赖的package包/类
@Override
public <T> T sendHttpGetRequest(String URL, Class<T> type)
throws IOException {
HttpRequest httpRequest = Pools.obtain(HttpRequest.class);
httpRequest.setMethod(Net.HttpMethods.GET);
httpRequest.setTimeOut(TIMEOUT);
httpRequest.setUrl(URL);
try {
return sendHttpRequest(httpRequest, type);
} finally {
Pools.free(httpRequest);
}
}
示例8: getJsonList
import com.badlogic.gdx.Net.HttpRequest; //导入方法依赖的package包/类
public void getJsonList() {
HttpRequest httpRequest = new HttpRequest(HttpMethods.GET);
httpRequest.setUrl("http://24.222.27.154/highscores.json");
Gdx.net.sendHttpRequest(httpRequest, new HttpResponseListener() {
@Override
public void handleHttpResponse(HttpResponse httpResponse) {
result = httpResponse.getResultAsString();
Gdx.app.postRunnable(new Runnable() {
@Override
public void run() {
grabHighScores();
createHighScores();
}
});
}
@Override
public void failed(Throwable t) {
Gdx.app.postRunnable(new Runnable() {
@Override
public void run() {
createHighScores();
if (highScoreStage != null) {
Dialog dialog = new Dialog("Error", new Skin(
Gdx.files.internal("data/uiskin.json")));
dialog.text("Connection Error");
dialog.button("OK");
dialog.show(highScoreStage);
}
}
});
result = "";
}
@Override
public void cancelled() {
}
});
// long time = System.currentTimeMillis();
// while(result == null) {
// if(System.currentTimeMillis() - time > 5000) {
// break;
// }
// }
//
// return result;
}
示例9: call
import com.badlogic.gdx.Net.HttpRequest; //导入方法依赖的package包/类
@Override
public Object call() throws Exception {
// Try to download update.json. If updateURL is not present, disable
// the update system
if (releaseInfo.getUpdateURL() != null) {
HttpRequest request = new HttpRequest("GET");
request.setUrl(releaseInfo.getUpdateURL());
Gdx.app.debug(LOG_TAG,
"Trying to retrieve update.json from url:"
+ releaseInfo.getUpdateURL());
Gdx.net.sendHttpRequest(request, new HttpResponseListener() {
@Override
public void handleHttpResponse(HttpResponse httpResponse) {
if (httpResponse.getStatus().getStatusCode() == 200) {
String data = httpResponse.getResultAsString();
Gdx.app.debug(LOG_TAG,
"Update.json fetched and read: " + data);
try {
UpdateInfo updateInfo = controller
.getApplicationAssets().fromJson(
UpdateInfo.class, data);
if (updateInfo != null) {
checkUpdateNeeded(updateInfo);
}
} catch (SerializationException e) {
Gdx.app.error(
LOG_TAG,
"An error occurred while reading update.json from "
+ releaseInfo.getUpdateURL()
+ ". The update system will be disabled.",
e);
setDone();
}
}
}
@Override
public void failed(Throwable t) {
Gdx.app.debug(
LOG_TAG,
"Error fetching update.json. Updater will be disabled",
t);
setDone();
}
@Override
public void cancelled() {
}
});
} else {
Gdx.app.debug(LOG_TAG,
"The update.json url is null. The update system will be disabled.");
setDone();
}
return null;
}