本文整理汇总了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");
}
示例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());
}
示例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());
}
示例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());
}
示例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);
}