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


Java HttpRequest.get方法代码示例

本文整理汇总了Java中com.github.kevinsawicki.http.HttpRequest.get方法的典型用法代码示例。如果您正苦于以下问题:Java HttpRequest.get方法的具体用法?Java HttpRequest.get怎么用?Java HttpRequest.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.github.kevinsawicki.http.HttpRequest的用法示例。


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

示例1: doInBackground

import com.github.kevinsawicki.http.HttpRequest; //导入方法依赖的package包/类
/**
 * Override this method to perform a computation on a background thread. The
 * specified parameters are the parameters passed to {@link #execute}
 * by the caller of this task.
 *
 * This method can call {@link #publishProgress} to publish updates
 * on the UI thread.
 *
 * @param comicNumber The parameters of the task.
 * @return A result, defined by the subclass of this task.
 * @see #onPreExecute()
 * @see #onPostExecute
 * @see #publishProgress
 */
@Override protected Comic doInBackground(Integer... comicNumber) {
    // Should only ever be a single comic number, so let's enforce it.
    if (comicNumber != null && comicNumber.length == 1) {
        HttpRequest request = HttpRequest.get(ComicUtil.getComicApiUrl(comicNumber[0]));
        if (request.code() == 200) {
            String response = request.body();
            request.disconnect();
            Gson gson = new Gson();
            Comic comicResponse = gson.fromJson(response, Comic.class);

            return comicResponse;
        } else {
            request.disconnect();
            return null;
        }
    }
    return null;
}
 
开发者ID:DavidTPate,项目名称:XKCD-Reader,代码行数:33,代码来源:ComicFragment.java

示例2: test02

import com.github.kevinsawicki.http.HttpRequest; //导入方法依赖的package包/类
@Test
public void test02() throws Exception {
    //49
    ObjectMapper mapper = new ObjectMapper();
    List<String> ret = new ArrayList<>();
    String url = "https://xueqiu.com/stock/cata/stocklist.json?page=";
    String param = "&size=100&order=desc&orderby=percent&type=11%2C12&_=1461851096446";
    for (int i = 1; i <= 50; i++) {
        String dest = url + i + param;
        HttpRequest req = HttpRequest.get(dest);
        req.header("Cookie", "xq_a_token=93b9123bccf67168e3adb0c07d89b9e1f6cc8db6;");
        String body = req.body();
        ret.add(body);

        JsonNode jsonNode = mapper.readTree(body);
        JsonNode stocks = jsonNode.get("stocks");
        stocks.forEach(st->{
            Stock stock = null;
            try {
                stock = mapper.readValue(st.toString(), Stock.class);
                DaoUtil.dao.insert(stock);
            } catch (Exception e) {
                e.printStackTrace();
            }

        });
        Thread.sleep(500);
        System.out.println("fetch url " + dest + " result " + body);

    }
    System.out.println("final result---> " + mapper.writeValueAsString(ret));

}
 
开发者ID:jt120,项目名称:take,代码行数:34,代码来源:LoginTest.java

示例3: test05

import com.github.kevinsawicki.http.HttpRequest; //导入方法依赖的package包/类
@Test
public void test05() throws Exception {

    HttpRequest request = HttpRequest.get("http://push3.gtimg.cn/q=sz300507,sz002629,sh603029,sz000099,sz300277,sz002684,sh600538,sz002097,sz002795,sh603868,sz300508,sz002729,sz000665,sz300073,sz300481,sz300097,sz002793,sh603701,sh603726,sh600073,sz300466,sz300509,sz002106,sh603822,sz300249&m=push&r=864212903");
    String body = request.body();
    System.out.println(body);
}
 
开发者ID:jt120,项目名称:take,代码行数:8,代码来源:LoginTest.java

示例4: doInBackground

import com.github.kevinsawicki.http.HttpRequest; //导入方法依赖的package包/类
protected String doInBackground(String... params) {
    HttpRequest request = HttpRequest.get(UPLOAD_URL,true, params);
    Log.d("jabe", "开始上传 : " + request.url());
    if (request.code() == 200) {
        return request.body();
    } else {
        return request.code()+"";
    }
}
 
开发者ID:jabelai,项目名称:location-phonegap,代码行数:10,代码来源:LocationCacheService.java

示例5: connect

import com.github.kevinsawicki.http.HttpRequest; //导入方法依赖的package包/类
public String connect(String postKey, String postValue) throws IOException
{
	HttpRequest request = HttpRequest.get(mConnection);
	StringBuilder output = new StringBuilder();

	request.readTimeout(5000);

	if (postKey != null && postValue != null)
		request.send(postKey + "=" + URLEncoder.encode(postValue, "UTF-8")).receive(output);
	else
		request.receive(output);

	return output.toString();
}
 
开发者ID:genonbeta,项目名称:TrebleShot,代码行数:15,代码来源:RemoteServer.java

示例6: render

import com.github.kevinsawicki.http.HttpRequest; //导入方法依赖的package包/类
@Override
public void render(String filename) throws InterruptedException, IOException {
    String dot = read(path + filename + ".dot");
    HttpRequest httpRequest = HttpRequest.get(GOOGLE_CHART_API, true, "cht", "gv", "chl", dot);
    if (httpRequest.ok()) {
        try (InputStream is = httpRequest.stream()) {
            Files.copy(is, Paths.get(path + filename + getImageExtension()));
        }
    } else {
        throw new DotDiagramException("Errors calling Graphviz chart.googleapis.com");
    }
}
 
开发者ID:LivingDocumentation,项目名称:dot-diagram,代码行数:13,代码来源:GoogleChartDotWriter.java

示例7: doInBackground

import com.github.kevinsawicki.http.HttpRequest; //导入方法依赖的package包/类
/**
 * Override this method to perform a computation on a background thread. The
 * specified parameters are the parameters passed to {@link #execute}
 * by the caller of this task.
 *
 * This method can call {@link #publishProgress} to publish updates
 * on the UI thread.
 *
 * @param params The parameters of the task.
 * @return A result, defined by the subclass of this task.
 * @see #onPreExecute()
 * @see #onPostExecute
 * @see #publishProgress
 */
@Override protected Comic doInBackground(Void... params) {
    HttpRequest request = HttpRequest.get(Constants.API.LATEST_COMIC_ENDPOINT);
    if (request.code() == 200) {
        String response = request.body();
        request.disconnect();
        Gson gson = new Gson();
        Comic comicResponse = gson.fromJson(response, Comic.class);

        return comicResponse;
    } else {
        request.disconnect();
        return null;
    }
}
 
开发者ID:DavidTPate,项目名称:XKCD-Reader,代码行数:29,代码来源:ComicFragmentActivity.java

示例8: doInBackground

import com.github.kevinsawicki.http.HttpRequest; //导入方法依赖的package包/类
/**
 * Override this method to perform a computation on a background thread. The
 * specified parameters are the parameters passed to {@link #execute}
 * by the caller of this task.
 *
 * This method can call {@link #publishProgress} to publish updates
 * on the UI thread.
 *
 * @param params The parameters of the task.
 * @return A result, defined by the subclass of this task.
 * @see #onPreExecute()
 * @see #onPostExecute
 * @see #publishProgress
 */
@Override protected Comic doInBackground(Void... params) {
    HttpRequest request = HttpRequest.get("http://xkcd.com/info.0.json");
    if (request.code() == 200) {
        String response = request.body();
        request.disconnect();
        Gson gson = new Gson();
        Comic comicResponse = gson.fromJson(response, Comic.class);

        return comicResponse;
    } else {
        request.disconnect();
        return null;
    }
}
 
开发者ID:DavidTPate,项目名称:XKCD-Reader,代码行数:29,代码来源:CurrentComic.java

示例9: createRequest

import com.github.kevinsawicki.http.HttpRequest; //导入方法依赖的package包/类
private HttpRequest createRequest(AuthenticationProvider authProvider, String project,
		String branch, String reviewer) {
	QueryBuilder queryBuilder = new QueryBuilder(server.getUrl(), authProvider.isAnonymous());
	queryBuilder.setProject(project);
	queryBuilder.setBranch(branch);
	queryBuilder.setReviewer(reviewer);
	String queryUrl = queryBuilder.createQueryUrl();
	HttpRequest request = HttpRequest.get(queryUrl);
	request.acceptGzipEncoding().uncompress(true).trustAllCerts().trustAllHosts();
	request.accept(HttpRequest.CONTENT_TYPE_JSON);
	return request;
}
 
开发者ID:plusonelabs,项目名称:dashclock-gerrit,代码行数:13,代码来源:Gerrit.java

示例10: createRequest

import com.github.kevinsawicki.http.HttpRequest; //导入方法依赖的package包/类
private HttpRequest createRequest(GerritEndpoint endpoint, String loginUrl) {
	HttpRequest request = HttpRequest.get(loginUrl);
	request.acceptGzipEncoding().uncompress(true).trustAllCerts().trustAllHosts();
	request.basic(endpoint.getUsername(), endpoint.getPassword());
	return request;
}
 
开发者ID:plusonelabs,项目名称:dashclock-gerrit,代码行数:7,代码来源:BasicAuthWithCookieAuthenticationProvider.java

示例11: run

import com.github.kevinsawicki.http.HttpRequest; //导入方法依赖的package包/类
@Override
public void run() {
	
	try {
		
		HttpRequest request = HttpRequest.get(Main.SERVER_URL + "/level/get?id=" + id);
			request.trustAllCerts();
			request.trustAllHosts();
		
		objects = new ArrayList<GameObject>();
		
		level = new Level(request.body(), game);
		objects = new ArrayList<GameObject>(level.getObjects());
		width = level.getWidth();
		height = level.getHeight();
		
		loading = false;
		
		translateX = Main.WIDTH / 2 - level.getWidth() * 16;
		translateY = Main.HEIGHT / 2 - level.getHeight() * 16;
		
	} catch (HttpRequestException | ParserConfigurationException
			| SAXException | IOException | SlickException e) {
		
		error = true;
		
	}
	
}
 
开发者ID:CyboticCatfish,项目名称:code404,代码行数:30,代码来源:Game.java

示例12: get

import com.github.kevinsawicki.http.HttpRequest; //导入方法依赖的package包/类
/**
 * (http) get
 * @param address       The address of the API
 * @param apiKey        The username for basic authentication
 * @param apiPassword   The password for basic authentication
 * @param requestType   The URI part of the API method
 * @return              The request object
 * @throws Exception
 */
public HttpRequest get(String address, String apiKey, String apiPassword, String requestType) throws Exception {
    HttpRequest request = HttpRequest.get(new URL(address));
    request.basic(apiKey, apiPassword);
    request.accept(String.format("application/%s", requestType));
    return request;
}
 
开发者ID:kfrancis,项目名称:Chargify.Java,代码行数:16,代码来源:Requester.java


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