Example usage for org.apache.http.client.methods HttpUriRequest setHeader

List of usage examples for org.apache.http.client.methods HttpUriRequest setHeader

Introduction

In this page you can find the example usage for org.apache.http.client.methods HttpUriRequest setHeader.

Prototype

void setHeader(String str, String str2);

Source Link

Usage

From source file:org.energy_home.jemma.utils.rest.RestClient.java

private HttpResponse send(HttpUriRequest uriRequest) throws ClientProtocolException, IOException {
    uriRequest.setHeader("Accept", HTTP_CONTENT_TYPE);
    return httpClient.execute(uriRequest, httpContext);
}

From source file:io.gs2.model.BasicGs2Credential.java

@Override
public void authorized(HttpUriRequest request, String service, String module, String function, Long timestamp) {
    String sign = new Base64().encodeAsString(SignUtil.sign(getClientSecret(), module, function, timestamp));
    request.setHeader("X-GS2-CLIENT-ID", getClientId());
    request.setHeader("X-GS2-REQUEST-TIMESTAMP", String.valueOf(timestamp));
    request.setHeader("X-GS2-REQUEST-SIGN", sign);
}

From source file:org.mythdroid.services.JSONClient.java

private InputStream RequestStream(HttpUriRequest req) throws IOException {

    req.setHeader("Accept", "application/json"); //$NON-NLS-1$ //$NON-NLS-2$
    LogUtil.debug("JSON request: " + req.getURI().toString()); //$NON-NLS-1$

    try {/*from w  w  w .j  a  v  a  2s  .c o  m*/
        fetcher = new HttpFetcher(req, Globals.muxConns);
        return fetcher.getInputStream();
    } catch (SocketTimeoutException e) {
        throw new IOException(Messages.getString("JSONClient.0") + //$NON-NLS-1$
                req.getURI().getHost() + ":" + req.getURI().getPort() //$NON-NLS-1$
        );
    } catch (ClientProtocolException e) {
        ErrUtil.logErr(e);
        return null;
    }

}

From source file:cn.com.loopj.android.http.RangeFileAsyncHttpResponseHandler.java

public void updateRequestHeaders(HttpUriRequest uriRequest) {
    if (file.exists() && file.canWrite())
        current = file.length();// ww  w  . j  a v  a 2 s.c o m
    if (current > 0) {
        append = true;
        uriRequest.setHeader("Range", "bytes=" + current + "-");
    }
}

From source file:com.amytech.android.library.utils.asynchttp.RangeFileAsyncHttpResponseHandler.java

public void updateRequestHeaders(HttpUriRequest uriRequest) {
    if (mFile.exists() && mFile.canWrite())
        current = mFile.length();/*w  w w . j  a  va  2  s .  c  o m*/
    if (current > 0) {
        append = true;
        uriRequest.setHeader("Range", "bytes=" + current + "-");
    }
}

From source file:org.mythdroid.services.JSONClient.java

private JSONObject Request(HttpUriRequest req) throws IOException {

    req.setHeader("Accept", "application/json"); //$NON-NLS-1$ //$NON-NLS-2$
    LogUtil.debug("JSON request: " + req.getURI().toString()); //$NON-NLS-1$

    String res = null;//from   w ww  . j a  v  a 2 s .  c  o m

    try {
        res = new HttpFetcher(req, Globals.muxConns).getContent();
    } catch (SocketTimeoutException e) {
        throw new IOException(Messages.getString("JSONClient.0") + //$NON-NLS-1$
                req.getURI().getHost() + ":" + req.getURI().getPort() //$NON-NLS-1$
        );
    } catch (ClientProtocolException e) {
        ErrUtil.logErr(e);
        throw new IOException(e.getMessage());
    }

    LogUtil.debug("JSON response: " + res); //$NON-NLS-1$

    try {
        return new JSONObject(res);
    } catch (JSONException e) {
        ErrUtil.logErr(e);
        throw new IOException(e.getMessage());
    }

}

From source file:com.foundationdb.http.CsrfProtectionITBase.java

@Test
public void getAllowed1() throws Exception {
    HttpUriRequest request = new HttpGet(defaultURI());
    request.setHeader("Referer", "http://somewhere.com");

    response = client.execute(request);//from  ww w .  jav a  2s  .c  o  m
    assertEquals("status", HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
}

From source file:com.foundationdb.http.CsrfProtectionITBase.java

@Test
public void getAllowed2() throws Exception {
    HttpUriRequest request = new HttpGet(defaultURI());
    request.setHeader("Referer", "https://coolest.site.edu:4320");

    response = client.execute(request);/*from  w ww .ja  v a  2 s .  com*/
    assertEquals("status", HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
}

From source file:com.foundationdb.http.CsrfProtectionITBase.java

@Test
public void requestBlockedWithEmptyReferer() throws Exception {
    HttpUriRequest request = new HttpPut(defaultURI());
    request.setHeader("Referer", "");

    response = client.execute(request);/*from ww  w.j  a v  a 2  s.c om*/
    assertEquals("status", HttpStatus.SC_FORBIDDEN, response.getStatusLine().getStatusCode());
    assertThat("reason", response.getStatusLine().getReasonPhrase(), containsString("Referer"));
}

From source file:com.foundationdb.http.CsrfProtectionITBase.java

@Test
public void putBlockedWithBlankReferer() throws Exception {
    HttpUriRequest request = new HttpPut(defaultURI());
    request.setHeader("Referer", "");

    response = client.execute(request);/* w  ww . j ava  2s . c  om*/
    assertEquals("status", HttpStatus.SC_FORBIDDEN, response.getStatusLine().getStatusCode());
    assertThat("reason", response.getStatusLine().getReasonPhrase(), containsString("Referer"));
}