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


Java HttpRequestWithBody.header方法代码示例

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


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

示例1: updatePublishRepo

import com.mashape.unirest.request.HttpRequestWithBody; //导入方法依赖的package包/类
public void updatePublishRepo(String prefix, String distribution) throws AptlyRestException
{
    try {
        HttpRequestWithBody req = Unirest.put(mSite.getUrl() + "/api/publish/"
                                              + prefix + "/" + distribution);
        req = req.header("Content-Type", "application/json");
        JSONObject options = new JSONObject();
        options.put("ForceOverwrite", true);
        options.put("Signing",buildSigningJson());
        req.body(options.toString());
        JSONObject res = sendRequest(req);
        
    } 
    catch (AptlyRestException ex) {
        mLogger.printf("Failed to publish repo: " + ex.toString());
        throw ex;
    }
}
 
开发者ID:zgyarmati,项目名称:aptly-plugin,代码行数:19,代码来源:AptlyRestClient.java

示例2: main

import com.mashape.unirest.request.HttpRequestWithBody; //导入方法依赖的package包/类
public static void main(String[] args) throws UnirestException {
    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    HttpRequestWithBody requestWithBody = Unirest.put("http://192.168.1.103:9200/get-together/new-events/4");
    HttpRequestWithBody requestBody = requestWithBody.header("content-type", MediaType.APPLICATION_JSON_VALUE);
    Map<String, Object> body = new HashMap<>();
    body.put("name", "Late Night with Elasticsearch");
    body.put("date", DateFormatUtils.ISO_8601_EXTENDED_DATETIME_TIME_ZONE_FORMAT.format(new Date()));
    RequestBodyEntity requestBodyEntity = requestBody.body(gson.toJson(body));
    System.out.println(gson.toJson(gson.fromJson(requestBodyEntity.asString().getBody(), Object.class)));
}
 
开发者ID:PkayJava,项目名称:MBaaS,代码行数:11,代码来源:ElasticSearch.java

示例3: createBody

import com.mashape.unirest.request.HttpRequestWithBody; //导入方法依赖的package包/类
private String createBody(HttpRequestWithBody post, Object bean) {
    if (firstConsume != null && firstConsume.indexOf("/xml") >= 0) {
        post.header("Content-Type", "application/xml;charset=UTF-8");
        return Xmls.marshal(bean);
    } else {
        post.header("Content-Type", "application/json;charset=UTF-8");
        return ValueUtils.processValue(bean);
    }
}
 
开发者ID:bingoohuang,项目名称:spring-rest-client,代码行数:10,代码来源:RestReq.java

示例4: executePostQuery

import com.mashape.unirest.request.HttpRequestWithBody; //导入方法依赖的package包/类
/**
 * Test the {@link FreesoundClient#executeQuery(Query)} method, to ensure it correctly constructs and submits an
 * HTTP POST request, and processes the results.
 *
 * @param mockUnirest Mock version of the {@link Unirest} library
 * @param mockPostRequest Mock {@link HttpRequestWithBody} representing a POST call
 * @param mockHttpResponse Mock {@link HttpResponse}
 * @param mockResultsMapper Mock {@link SoundMapper}
 *
 * @throws Exception Any exceptions thrown in test
 */
@SuppressWarnings("static-access")
@Test
public void executePostQuery(
		@Mocked final Unirest mockUnirest,
		@Mocked final HttpRequestWithBody mockPostRequest,
		@Mocked final HttpResponse<JsonNode> mockHttpResponse,
		@Mocked final SoundMapper mockResultsMapper) throws Exception {
	final Sound sound = new Sound();
	new Expectations() {
		{
			mockUnirest.post(FreesoundClient.API_ENDPOINT + TEST_PATH); result = mockPostRequest;

			mockPostRequest.header("Authorization", "Token " + CLIENT_SECRET);
			mockPostRequest.routeParam(ROUTE_ELEMENT, ROUTE_ELEMENT_VALUE);
			mockPostRequest.fields(with(new Delegate<HashMap<String, Object>>() {
				@SuppressWarnings("unused")
				void checkRequestParameters(final Map<String, Object> queryParameters) {
					assertNotNull(queryParameters);
					assertTrue(queryParameters.size() == 1);
					assertEquals(QUERY_PARAMETER_VALUE, queryParameters.get(QUERY_PARAMETER));
				}
			}));

			mockPostRequest.asJson(); result = mockHttpResponse;
			mockHttpResponse.getStatus(); result = 200;
			mockResultsMapper.map(mockHttpResponse.getBody().getObject()); result = sound;
		}
	};

	final JSONResponseQuery<Sound> query = new TestJSONResponseQuery(HTTPRequestMethod.POST, mockResultsMapper);
	final Response<Sound> response = freesoundClient.executeQuery(query);

	assertSame(sound, response.getResults());
}
 
开发者ID:Sonoport,项目名称:freesound-java,代码行数:46,代码来源:FreesoundClientTest.java

示例5: execute

import com.mashape.unirest.request.HttpRequestWithBody; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public ResponseWrapper<RECEIVE> execute(LittlstarApiClient apiClient, SEND data, StringPair... parameters)
        throws UnirestException {

    HttpRequestWithBody request = new HttpRequestWithBody(httpMethod, apiClient.getTLD() + apiCall);

    for(String key : routeParams) {
        boolean found = false;
        for(StringPair param : parameters) {
            if(param.getKey().equals(key)) {
                found = true;
                request.routeParam(key, param.getValue());
                break;
            }
        }
        if(!found) {
            throw new IllegalArgumentException("No value passed for required API call key "+key);
        }
    }

    //always include the Application Token in the header if it's set
    if(apiClient.getApplicationToken() != null) {
        request.header("X-AppToken", apiClient.getApplicationToken());
    }

    //if required, include the authenticated user's Apikey in the header
    if(requiresAuthentication) {
        request.header("X-Apikey", apiClient.getUserApiKey());
    }

    SendWrapper<SEND> sendWrapper = new SendWrapper<SEND>(data);

    //send the SendWrapper as JSON Payload, unless EmptyData is wrapped
    if(sendWrapper.toJson() != null) {
        request.header("content-type", "application/json")
                .body(sendWrapper.toJson());
    } else {
        //we need to put an empty body to execute the call
        request.body("");
    }

    String json = "";
    if(request.getBody() instanceof RequestBodyEntity && ((RequestBodyEntity)request.getBody()).getBody() != null) {
        json = request.asString().getBody();
    }

    return LittlstarApiClient.getGson(responseClass).fromJson(json, ResponseWrapper.class);
}
 
开发者ID:CrushedPixel,项目名称:littlstar-java-sdk,代码行数:49,代码来源:ApiCall.java

示例6: makePostRequest

import com.mashape.unirest.request.HttpRequestWithBody; //导入方法依赖的package包/类
/**
 * Method which uses OKHTTP to send a POST request to the specified URL saved
 * within the APIMethod class 
 * @throws UnirestException 
 */
@SuppressWarnings("unchecked")
private <T> T makePostRequest(ApiMethod method) throws RobinhoodApiException {
	
	HttpRequestWithBody request = Unirest.post(method.getBaseUrl());
	
		
	//Append each of the headers for the method
	Iterator<HttpHeaderParameter> headerIterator = method.getHttpHeaderParameters().iterator();
	while(headerIterator.hasNext()) {
		
		HttpHeaderParameter currentHeader = headerIterator.next();
		request.header(currentHeader.getKey(), currentHeader.getValue());
	}

	try {
           //Append the request body
           request.body(method.getUrlParametersAsPostBody());

           //Make the request
           HttpResponse<JsonNode> jsonResponse = request.asJson();

           //Parse the response with Gson
           Gson gson = new Gson();
           String responseJsonString = jsonResponse.getBody().toString();

           //If the response type for this is VOID (Meaning we are not expecting a response) do not
           //try to use Gson
           if(method.getReturnType() == Void.TYPE)
               return (T) Void.TYPE;

           T data = gson.fromJson(responseJsonString, method.getReturnType());
           return data;

       } catch (UnirestException ex) {

           System.err.println("[RobinhoodApi] Failed to communicate with Robinhood servers, request failed");

       }

	throw new RobinhoodApiException();
	
}
 
开发者ID:ConradWeiser,项目名称:Unofficial-Robinhood-Api,代码行数:48,代码来源:RequestManager.java


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