Package com.github.kevinsawicki.http

Examples of com.github.kevinsawicki.http.HttpRequest.contentType()


        postData.put("id", "r"+this._rid);

        this._rid++;

        // set content type to json
        request.contentType(HttpRequest.CONTENT_TYPE_JSON);
        request.acceptJson();
        request.send(postData.toString());

        // We force method call
        int statusCode = request.code();
View Full Code Here


    HttpURLConnection connection = mock( HttpURLConnection.class );
    when( connection.getURL() ).thenReturn( new URL( "http://test.com" ) );
    when( httpRequest.getConnection() ).thenReturn( connection );
    when( httpRequest.body() ).thenReturn( "test" );
    when( httpRequest.code() ).thenReturn( 200 );
    when( httpRequest.contentType() ).thenReturn( MediaType.TEXT_PLAIN.toString() );
    HashMap<String, List<String>> headers = new HashMap<String, List<String>>();
    List<String> values = new ArrayList<String>();
    values.add( "test" );
    headers.put( "test", values );
    when( httpRequest.headers() ).thenReturn( headers );
View Full Code Here

  String downloadString(String path) throws IOException {
    String fullUrl = serverUrl + path;
    HttpRequest httpRequest = newHttpRequest(new URL(fullUrl));
    try {
      String charset = getCharsetFromContentType(httpRequest.contentType());
      if (charset == null || "".equals(charset)) {
        charset = "UTF-8";
      }
      if (!httpRequest.ok()) {
        throw new IOException(MessageFormat.format(STATUS_RETURNED_BY_URL_IS_INVALID, fullUrl, httpRequest.code()));
View Full Code Here

            sb.setLength(sb.length() - 2);
            httpRequest.header("Cookie", sb.toString());
        }

        if (!Strings.isNullOrEmpty(when.getBody())) {
            httpRequest.contentType("application/json");
            httpRequest.send(when.getBody());
            System.out.println(when.getBody());
        }
        System.out.println();
View Full Code Here

                .setRouterPath("/api").setPort(WebServers.findAvailablePort()).build();
        server.start();
        try {
            HttpRequest httpRequest = HttpRequest.get(server.baseUrl() + "/api/test/test.txt");
            assertThat(httpRequest.code()).isEqualTo(200);
            assertThat(httpRequest.contentType()).isEqualTo("text/plain; charset=UTF-8");
            assertThat(httpRequest.body().trim()).isEqualTo("hello");

            httpRequest = HttpRequest.put(server.baseUrl() + "/api/test/test.txt").send("bonjour");
            assertThat(httpRequest.code()).isEqualTo(HttpStatus.NOT_FOUND.getCode());
        } finally {
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.