当前位置: 首页>>代码示例>>Java>>正文


Java HttpResponseListener类代码示例

本文整理汇总了Java中com.badlogic.gdx.Net.HttpResponseListener的典型用法代码示例。如果您正苦于以下问题:Java HttpResponseListener类的具体用法?Java HttpResponseListener怎么用?Java HttpResponseListener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


HttpResponseListener类属于com.badlogic.gdx.Net包,在下文中一共展示了HttpResponseListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: create

import com.badlogic.gdx.Net.HttpResponseListener; //导入依赖的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");
		}
	});
}
 
开发者ID:basherone,项目名称:libgdxcn,代码行数:22,代码来源:HttpRequestExample.java

示例2: sendRequest

import com.badlogic.gdx.Net.HttpResponseListener; //导入依赖的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(){

        }
    });
}
 
开发者ID:Xemplar,项目名称:NerdShooter,代码行数:24,代码来源:NetworkHandle.java

示例3: sendHttpRequest

import com.badlogic.gdx.Net.HttpResponseListener; //导入依赖的package包/类
@Override
public void sendHttpRequest(HttpRequest httpRequest, HttpResponseListener httpResponseListener) {

	URI uri = URI.create(httpRequest.getUrl());

	if (cookieMgr != null && !cookieMgr.isEmpty()) {
		String tempCookie = cookieMgr.getHeaderPayload(uri);
		httpRequest.setHeader(HttpClient.HeaderFields.COOKIE, tempCookie);
	}

	if (headerFields.size > 0) {
		for (Entry<String, String> entry : headerFields.entries()) {
			httpRequest.setHeader(entry.key, entry.value);
		}
	}
	// Listener instantiation below...
	Gdx.net.sendHttpRequest(httpRequest, new ResponseWrapper(httpResponseListener, uri));
}
 
开发者ID:failcoDave,项目名称:gdx-http,代码行数:19,代码来源:DefaultHttpClient.java

示例4: urlCheck

import com.badlogic.gdx.Net.HttpResponseListener; //导入依赖的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);
        }
    });

}
 
开发者ID:langurmonkey,项目名称:gaiasky,代码行数:27,代码来源:DesktopNetworkChecker.java

示例5: ga

import com.badlogic.gdx.Net.HttpResponseListener; //导入依赖的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() {

		}
	});
}
 
开发者ID:e-ucm,项目名称:ead,代码行数:25,代码来源:GATracker.java

示例6: cancelHttpRequest

import com.badlogic.gdx.Net.HttpResponseListener; //导入依赖的package包/类
public void cancelHttpRequest (HttpRequest httpRequest) {
	HttpResponseListener httpResponseListener = getFromListeners(httpRequest);

	if (httpResponseListener != null) {
		httpResponseListener.cancelled();
		removeFromConnectionsAndListeners(httpRequest);
	}
}
 
开发者ID:Radomiej,项目名称:JavityEngine,代码行数:9,代码来源:JavityNetJavaImpl.java

示例7: GET

import com.badlogic.gdx.Net.HttpResponseListener; //导入依赖的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;
			}
		});
	}
 
开发者ID:Radomiej,项目名称:JavityEngine,代码行数:38,代码来源:WWW.java

示例8: sendRequest

import com.badlogic.gdx.Net.HttpResponseListener; //导入依赖的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();
			}
		});

	}
 
开发者ID:TomGrill,项目名称:gdx-twitter,代码行数:36,代码来源:TwitterAPI.java

示例9: cancelHttpRequest

import com.badlogic.gdx.Net.HttpResponseListener; //导入依赖的package包/类
public void cancelHttpRequest (HttpRequest httpRequest) {				
	try {
		lock.lock();
		HttpResponseListener httpResponseListener = listeners.get(httpRequest);

		if (httpResponseListener != null) {
			httpResponseListener.cancelled();
			connections.remove(httpRequest);
			listeners.remove(httpRequest);
		}
	} finally {
		lock.unlock();
	}
}
 
开发者ID:basherone,项目名称:libgdxcn,代码行数:15,代码来源:NetJavaImpl.java

示例10: create

import com.badlogic.gdx.Net.HttpResponseListener; //导入依赖的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");
		}
	});
}
 
开发者ID:basherone,项目名称:libgdxcn,代码行数:32,代码来源:DownloadTest.java

示例11: getTAPData

import com.badlogic.gdx.Net.HttpResponseListener; //导入依赖的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;
}
 
开发者ID:langurmonkey,项目名称:gaiasky,代码行数:34,代码来源:GaiaCatalogWindow.java

示例12: loadClientId

import com.badlogic.gdx.Net.HttpResponseListener; //导入依赖的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;
	}
}
 
开发者ID:e-ucm,项目名称:ead,代码行数:44,代码来源:Tracker.java

示例13: JavityNetJavaImpl

import com.badlogic.gdx.Net.HttpResponseListener; //导入依赖的package包/类
public JavityNetJavaImpl () {
	asyncExecutor = new AsyncExecutor(10);
	connections = new ObjectMap<HttpRequest, HttpURLConnection>();
	listeners = new ObjectMap<HttpRequest, HttpResponseListener>();
}
 
开发者ID:Radomiej,项目名称:JavityEngine,代码行数:6,代码来源:JavityNetJavaImpl.java

示例14: putIntoConnectionsAndListeners

import com.badlogic.gdx.Net.HttpResponseListener; //导入依赖的package包/类
synchronized void putIntoConnectionsAndListeners (final HttpRequest httpRequest,
	final HttpResponseListener httpResponseListener, final HttpURLConnection connection) {
	connections.put(httpRequest, connection);
	listeners.put(httpRequest, httpResponseListener);
}
 
开发者ID:Radomiej,项目名称:JavityEngine,代码行数:6,代码来源:JavityNetJavaImpl.java

示例15: getFromListeners

import com.badlogic.gdx.Net.HttpResponseListener; //导入依赖的package包/类
synchronized HttpResponseListener getFromListeners (HttpRequest httpRequest) {
	HttpResponseListener httpResponseListener = listeners.get(httpRequest);
	return httpResponseListener;
}
 
开发者ID:Radomiej,项目名称:JavityEngine,代码行数:5,代码来源:JavityNetJavaImpl.java


注:本文中的com.badlogic.gdx.Net.HttpResponseListener类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。