Android HttpRequest - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android HttpRequest class.

This code example shows how to use the following methods: getParams, getRequestLine
            // expected 
        } 
    } 
 
    public void testRequestLine() throws Exception { 
        HttpRequest request = new BasicHttpRequest("GET", "/stuff");
        request.getParams().setParameter(
                CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_0);
        assertEquals("GET", request.getRequestLine().getMethod());
        assertEquals("/stuff", request.getRequestLine().getUri());
        assertEquals(HttpVersion.HTTP_1_0, request.getRequestLine().getProtocolVersion());
    } 
 
    public void testRequestLine2() throws Exception { 
        HttpRequest request = new BasicHttpRequest("GET", "/stuff", HttpVersion.HTTP_1_0);
        assertEquals("GET", request.getRequestLine().getMethod());
        assertEquals("/stuff", request.getRequestLine().getUri());
        assertEquals(HttpVersion.HTTP_1_0, request.getRequestLine().getProtocolVersion());
    } 
 
Full Snippet Info
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: addHeader, containsHeader, getParams
			throws HttpException, IOException { 
		if(request==null){
			throw new IllegalArgumentException("HTTP request may not be null");
		} 
		if(request instanceof HttpEntityEnclosingRequest){
			if(request.containsHeader(SOAP_Action)){
				throw new ProtocolException("SOAPAction header already present");				
			} 
			if(request.getParams().getParameter(SOAP_Action)!=null){
				request.addHeader(SOAP_Action,(String) request.getParams().getParameter(SOAP_Action));
			} 
		} 
	} 
 
} 
Full Snippet Info
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: addHeader, containsHeader
This code example shows how to use the following methods: containsHeader, getProtocolVersion, getRequestLine
 
        Assert.assertEquals(0, conn.getMetrics().getRequestCount());
 
        final HttpRequest request = conn.receiveRequestHeader();
        Assert.assertNotNull(request);
        Assert.assertEquals(HttpVersion.HTTP_1_1, request.getProtocolVersion());
        Assert.assertEquals("/", request.getRequestLine().getUri());
        Assert.assertEquals("GET", request.getRequestLine().getMethod());
        Assert.assertTrue(request.containsHeader("User-Agent"));
        Assert.assertEquals(1, conn.getMetrics().getRequestCount());
    } 
 
    @Test 
    public void testReadRequestEntity() throws Exception { 
        final String s = "POST / HTTP/1.1\r\nUser-Agent: test\r\nContent-Length: 3\r\n\r\n123";
        final ByteArrayInputStream instream = new ByteArrayInputStream(s.getBytes("ASCII"));
        Mockito.when(socket.getInputStream()).thenReturn(instream);
 
        conn.bind(socket);
 
Full Snippet Info
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: addHeader
		 * .com/auth/userinfo.email 
		 */} 
 
	@Override 
	public void processHttpRequest(HttpRequest request) {
		request.addHeader("provider", "GoogleOpenIDConnect");
		request.addHeader("response_type", "code");
		request.addHeader("token", mToken);
 
		request.addHeader("scope", "https://www.googleapis.com/auth/userinfo.email");
	} 
 
} 
Full Snippet Info
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: addHeader
        mAppname = appname;
    } 
 
    @Override 
    public void processHttpRequest(HttpRequest request) {
        request.addHeader("X-User-Id", mLogin);
        request.addHeader("X-Device-Id", mDeviceId);
        request.addHeader("X-Application-Name", mAppname);
        request.addHeader("X-Temporary-Authentication-Token", mToken);
        Log.d("TemporaryTokenRequestInterceptor", "processHttpRequest");
    } 
 
    @Override 
    public void processRequest(Request request, Connector connector) {
        request.put("X-User-Id", mLogin);
        request.put("X-Device-Id", mDeviceId);
        request.put("X-Application-Name", mAppname);
        request.put("X-Temporary-Authentication-Token", mToken);
        Log.d("TokenRequestInterceptor", "processRequest");
 
Full Snippet Info
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: getAllHeaders, getFirstHeader, getRequestLine
        assertNull(request);
        requestParser.fillBuffer(newChannel("\r\n"));
        request = requestParser.parse();
 
        assertNotNull(request);
        assertEquals("/whatever", request.getRequestLine().getUri());
        assertEquals(1, request.getAllHeaders().length);
        assertEquals("stuff more stuff", request.getFirstHeader("Some header").getValue());
    } 
 
    public void testParsingBadlyFoldedFirstHeader() throws Exception { 
        HttpParams params = new BasicHttpParams();
        SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128, params);
        HttpRequestFactory requestFactory = new DefaultHttpRequestFactory();
        NHttpMessageParser<HttpRequest> requestParser = new DefaultHttpRequestParser(inbuf, null, requestFactory, params);
 
        requestParser.fillBuffer(newChannel("GET /whatev"));
        HttpRequest request = requestParser.parse();
        assertNull(request);
        requestParser.fillBuffer(newChannel("er HTTP/1.1\r"));
Full Snippet Info
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: getRequestLine
    } 
 
    @Override 
    public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
        if (verboseLoggingEnabled()) { 
            v("Executing OAuthProcessor : " + request.getRequestLine().getUri());
        } 
        if (request == null) {
            throw new IllegalArgumentException("HTTP request may not be null");
        } 
        if (request instanceof HttpUriRequest && isInitialized()) {
            try { 
                CommonsHttpOAuthConsumer consumer = new CommonsHttpOAuthConsumer(consumerKey,
                        consumerSecret);
                consumer.setSendEmptyTokens(false);
                consumer.setTokenWithSecret(token, secret);
                consumer.sign(request);
            } catch (final OAuthMessageSignerException e) {
                e("OAuthMessageSignerException", e);
            } catch (final OAuthExpectationFailedException e) {

5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: getRequestLine
        mServer.registerHandler("*", new HttpRequestHandler() {
            public void handle( 
                    HttpRequest request,
                    HttpResponse response,
                    HttpContext context) throws HttpException, IOException {
                 String uri = request.getRequestLine().getUri();
                 response.setEntity(new StringEntity(uri));
            } 
        }); 
 
        mServer.start();
        mServerUrl = "http://localhost:" + mServer.getPort() + "/";
    } 
 
    protected void tearDown() throws Exception { 
        if (mServer != null) mServer.shutdown();
    } 
 
    @LargeTest 
    public void testThreadCheck() throws Exception { 
Full Snippet Info
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: addHeader, containsHeader

Related Android HttpRequest Questions & Answers:

Other Android HttpRequest Examples

50:	
51:				HttpRequestFactory httpRequestFactory = createRequestFactory(HTTP_TRANSPORT);
52:				HttpRequest request = httpRequestFactory
53:						.buildGetRequest(new GenericUrl(PLACES_SEARCH_URL));
54:				request.getUrl().put("key", API_KEY);
-
80:	
81:				HttpRequestFactory httpRequestFactory = createRequestFactory(HTTP_TRANSPORT);
82:				HttpRequest request = httpRequestFactory
83:						.buildGetRequest(new GenericUrl(PLACES_DETAILS_URL));
84:				request.getUrl().put("key", API_KEY);
-
102:				final HttpTransport transport) {
103:			return transport.createRequestFactory(new HttpRequestInitializer() {
104:				public void initialize(HttpRequest request) {
105:					GoogleHeaders headers = new GoogleHeaders();
106:					headers.setApplicationName("AndroidHive-Places-Test");

Read More

See Code Examples for Android HttpRequest Methods: