本文整理汇总了Java中com.badlogic.gdx.Net.HttpResponse类的典型用法代码示例。如果您正苦于以下问题:Java HttpResponse类的具体用法?Java HttpResponse怎么用?Java HttpResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpResponse类属于com.badlogic.gdx.Net包,在下文中一共展示了HttpResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import com.badlogic.gdx.Net.HttpResponse; //导入依赖的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: urlCheck
import com.badlogic.gdx.Net.HttpResponse; //导入依赖的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);
}
});
}
示例3: handleHttpResponse
import com.badlogic.gdx.Net.HttpResponse; //导入依赖的package包/类
@Override
public void handleHttpResponse(HttpResponse httpResponse)
{
downloaders.add(this);
internalToAbsolute(".tmp/").file().mkdir();
temp.parent().mkdirs();
try (ReadableByteChannel rbc = Channels.newChannel(httpResponse.getResultAsStream());
FileOutputStream fos = new FileOutputStream(out))
{
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
tempFiles.put(filename, temp);
Gdx.app.log("Download", "Finished downloading " + filename);
} catch (IOException e)
{
e.printStackTrace();
out.delete();
}
downloaders.removeValue(this, false);
success.run();
}
示例4: ga
import com.badlogic.gdx.Net.HttpResponse; //导入依赖的package包/类
/**
* Sends the given payload to backend
*/
private void ga(String payload) {
HttpRequest request = new HttpRequest("POST");
request.setContent("v=1&tid=" + tracker + "&an=eAdventureDesktop&av="
+ version + "&cid=" + cid + "&" + payload);
Gdx.net.sendHttpRequest(request, new HttpResponseListener() {
@Override
public void handleHttpResponse(HttpResponse httpResponse) {
}
@Override
public void failed(Throwable t) {
}
@Override
public void cancelled() {
}
});
}
示例5: GET
import com.badlogic.gdx.Net.HttpResponse; //导入依赖的package包/类
public void GET(String query) {
if (work)
return;
work = true;
HttpRequestBuilder requestBuilder = new HttpRequestBuilder();
HttpRequest request = requestBuilder.newRequest().url(urlString).timeout(timeout).content(query).method(HttpMethods.GET).build();
final WWW my = this;
Gdx.net.sendHttpRequest(request, new HttpResponseListener() {
public void handleHttpResponse(HttpResponse httpResponse) {
responseBytes = httpResponse.getResult();
// Gdx.app.log("WWW", "Response: " + responseBytes.length);
// Gdx.app.log("WWW", "Status: " + httpResponse.getStatus().getStatusCode());
work = false;
if (wwwResponseListener != null) {
Gdx.app.postRunnable(new Runnable() {
public void run() {
wwwResponseListener.httpResponseListener(my);
}
});
}
}
public void failed(Throwable t) {
Gdx.app.error(WWW.class.getSimpleName(), "failed: " + t);
work = false;
}
public void cancelled() {
Gdx.app.error(WWW.class.getSimpleName(), "cancelled");
work = false;
}
});
}
示例6: sendRequest
import com.badlogic.gdx.Net.HttpResponse; //导入依赖的package包/类
private void sendRequest(final TwitterRequest twitterRequest, final TwitterResponseListener listener) {
HttpRequestBuilder requestBuilder = new HttpRequestBuilder();
HttpRequest httpRequest = requestBuilder.newRequest().method(twitterRequest.getRequestType().name()).url(twitterRequest.getUrl()).build();
// System.out.println(twitterRequest.build().getHeader());
twitterRequest.build();
httpRequest.setHeader("Authorization", twitterRequest.getHeader());
httpRequest.setContent(twitterRequest.getData());
httpRequest.setTimeOut(config.TWITTER_REQUEST_TIMEOUT);
Gdx.net.sendHttpRequest(httpRequest, new HttpResponseListener() {
@Override
public void handleHttpResponse(HttpResponse httpResponse) {
if (httpResponse.getStatus().getStatusCode() == 200) {
listener.success(httpResponse.getResultAsString());
} else {
listener.apiError(httpResponse.getStatus(), httpResponse.getResultAsString());
}
}
@Override
public void failed(Throwable t) {
listener.httpError(t);
}
@Override
public void cancelled() {
listener.cancelled();
}
});
}
示例7: handleHttpResponse
import com.badlogic.gdx.Net.HttpResponse; //导入依赖的package包/类
@Override
public void handleHttpResponse(HttpResponse httpResponse) {
String result = httpResponse.getResultAsString();
rs = json.fromJson(RemoteScore.class, result);
Gdx.app.debug("Score response", result);
Gdx.app.debug("Remote score got",
"Date : " + rs.getPlayDate() +
" / Player name : " + rs.getPlayerName() +
" / Score : " + rs.getScore());
}
示例8: handleHttpResponse
import com.badlogic.gdx.Net.HttpResponse; //导入依赖的package包/类
@Override
public void handleHttpResponse(HttpResponse httpResponse) {
HttpStatus status = httpResponse.getStatus();
if (status.getStatusCode() >= 200 && status.getStatusCode() < 300) {
String result = httpResponse.getResultAsString();
Gdx.app.debug("Score response", "ScoresList recieved !");
Gdx.app.debug("Score response", result);
@SuppressWarnings("unchecked")
LinkedList<JsonValue> list = json.fromJson(LinkedList.class, result);
if (list != null) {
for (JsonValue jsonValue : list) {
remoteScores.add(json.readValue(RemoteScore.class, jsonValue));
}
Gdx.app.debug("Remote list size", ""+remoteScores.size());
} else {
Gdx.app.debug("Score response", "No data to process !");
}
Gdx.app.debug("Score response", "Process data");
processor.processList(remoteScores);
} else {
Gdx.app.debug("Score response", "http error, code : "+status.getStatusCode());
showDialog();
}
}
示例9: handleHttpResponse
import com.badlogic.gdx.Net.HttpResponse; //导入依赖的package包/类
@Override
public void handleHttpResponse(HttpResponse httpResponse) {
if (cookieMgr != null) {
List<String> cookieStrings = httpResponse.getHeaders().get("Set-Cookie");
if (cookieStrings != null) {
for (String cookie : cookieStrings) {
cookieMgr.registerSetCookieHeader(cookie, sourceUri);
}
cookieMgr.save();
}
}
listener.handleHttpResponse(httpResponse);
}
示例10: create
import com.badlogic.gdx.Net.HttpResponse; //导入依赖的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");
}
});
}
示例11: setText
import com.badlogic.gdx.Net.HttpResponse; //导入依赖的package包/类
void setText (HttpResponse httpResponse) {
final String newText = httpResponse.getResultAsString();
Gdx.app.postRunnable(new Runnable() {
public void run () {
text = newText;
}
});
}
示例12: getTAPData
import com.badlogic.gdx.Net.HttpResponse; //导入依赖的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;
}
示例13: loadClientId
import com.badlogic.gdx.Net.HttpResponse; //导入依赖的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;
}
}
示例14: POST
import com.badlogic.gdx.Net.HttpResponse; //导入依赖的package包/类
public void POST(Object form) {
if (work)
return;
work = true;
HttpRequestBuilder requestBuilder = new HttpRequestBuilder();
HttpRequest request = requestBuilder.newRequest().url(urlString).timeout(timeout).jsonContent(form).method(HttpMethods.POST)
.build();
final WWW my = this;
Gdx.net.sendHttpRequest(request, new HttpResponseListener() {
public void handleHttpResponse(final HttpResponse httpResponse) {
responseBytes = httpResponse.getResult();
// Gdx.app.log(WWW.class.getSimpleName(), "response bytes: " + responseBytes.length + " response string: "
// + httpResponse.getResultAsString() + " Code: " + httpResponse.getStatus().getStatusCode());
statusCode = httpResponse.getStatus().getStatusCode();
work = false;
if (wwwResponseListener != null) {
Gdx.app.postRunnable(new Runnable() {
public void run() {
wwwResponseListener.httpResponseListener(my);
}
});
}
}
public void failed(Throwable t) {
Gdx.app.error(WWW.class.getSimpleName(), "failed: " + t);
work = false;
}
public void cancelled() {
Gdx.app.error(WWW.class.getSimpleName(), "cancelled");
work = false;
}
});
}
示例15: handleHttpResponse
import com.badlogic.gdx.Net.HttpResponse; //导入依赖的package包/类
@Override
public void handleHttpResponse(HttpResponse httpResponse) {
Gdx.app.debug("Score response", httpResponse.getResultAsString());
}