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


Java HttpRequestWithBody.basicAuth方法代码示例

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


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

示例1: fetchSchemaFromRemote

import com.mashape.unirest.request.HttpRequestWithBody; //导入方法依赖的package包/类
public static String fetchSchemaFromRemote(String url, String basicAuthUsername, String basicAuthPassword) {
    Map<String, String> bodyMap = new HashMap<>();
    bodyMap.put("query", introspectionQuery());
    bodyMap.put("variables", null);

    HttpRequestWithBody requestWithBody = Unirest.post(url)
            .header("Content-Type", "application/json")
            .header("accept", "application/json");

    // basic auth
    if (basicAuthUsername != null && basicAuthPassword != null) {
        requestWithBody.basicAuth(basicAuthUsername, basicAuthPassword);
    }

    // body
    RequestBodyEntity requestBodyEntity = requestWithBody.body(bodyMap);

    HttpResponse<JsonNode> jsonNodeHttpResponse;
    try {
        jsonNodeHttpResponse = requestBodyEntity.asJson();
    } catch (UnirestException e) {
        throw new RuntimeException(e);
    }

    return Util.convertStreamToString(jsonNodeHttpResponse.getRawBody(), "UTF-8");
}
 
开发者ID:tinnou,项目名称:graphql-codegen,代码行数:27,代码来源:Util.java

示例2: post

import com.mashape.unirest.request.HttpRequestWithBody; //导入方法依赖的package包/类
public void post() throws Exception {
    HttpRequestWithBody req = Unirest.post(url);
    HttpResponse resp;

    if (id != null && pwd != null) {
        req.basicAuth(id, pwd);
    }

    resp = req
            .header("content-type", "application/json")
            .body("{'nanostamp': " + System.nanoTime() + "}")
            .asString();

    assertEquals("check status code",
            HttpStatus.SC_CREATED, resp.getStatus());
}
 
开发者ID:SoftInstigate,项目名称:restheart,代码行数:17,代码来源:LoadPutPT.java

示例3: postWitId

import com.mashape.unirest.request.HttpRequestWithBody; //导入方法依赖的package包/类
public void postWitId() throws Exception {
    HttpRequestWithBody req = Unirest.post(url);
    HttpResponse resp;

    if (id != null && pwd != null) {
        req.basicAuth(id, pwd);
    }

    resp = req
            .header("content-type", "application/json")
            .body("{'_id': {'$oid': '"
                    + new ObjectId().toString()
                    + "'}, 'nanostamp': "
                    + System.nanoTime() + "}")
            .asString();

    assertEquals(
            "check status code",
            HttpStatus.SC_CREATED,
            resp.getStatus());
}
 
开发者ID:SoftInstigate,项目名称:restheart,代码行数:22,代码来源:LoadPutPT.java

示例4: put

import com.mashape.unirest.request.HttpRequestWithBody; //导入方法依赖的package包/类
public void put() throws Exception {
    String _url = url + "/" + new ObjectId().toString();

    HttpRequestWithBody req = Unirest.put(_url);
    HttpResponse resp;

    if (id != null && pwd != null) {
        req.basicAuth(id, pwd);
    }

    resp = req
            .header("content-type", "application/json")
            .body("{'nanostamp': " + System.nanoTime() + "}")
            .asString();

    assertEquals(
            "check status code",
            HttpStatus.SC_CREATED,
            resp.getStatus());
}
 
开发者ID:SoftInstigate,项目名称:restheart,代码行数:21,代码来源:LoadPutPT.java

示例5: putUrl

import com.mashape.unirest.request.HttpRequestWithBody; //导入方法依赖的package包/类
public void putUrl() throws Exception {
    String _url = this.url;

    HttpRequestWithBody req = Unirest.put(_url);
    HttpResponse resp;

    if (id != null && pwd != null) {
        req.basicAuth(id, pwd);
    }

    resp = req
            .header("content-type", "application/json")
            .body("{'nanostamp': " + System.nanoTime() + "}")
            .asString();

    assertTrue(
            "check status code",
            resp.getStatus() == HttpStatus.SC_CREATED
            || resp.getStatus() == HttpStatus.SC_OK);
}
 
开发者ID:SoftInstigate,项目名称:restheart,代码行数:21,代码来源:LoadPutPT.java


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