You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Eugeny N Dzhurinsky <eu...@jdevelop.com> on 2005/09/20 15:46:37 UTC

URI encoding

Could somebody please advice:
I created spider for the WEB using the HTTPClient
In this parser I always tried to use
new URI(URIString, false)

but for some reason the URLs looking like
http://www.vlissingen.nl/upload/207353_340_1127124319551-voetbal7_%28LM%29.jpg

are reported as broken URLs

What do I do in the wrong way.

-- 
Eugene N Dzhurinsky

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Re: URI encoding

Posted by Eugeny N Dzhurinsky <eu...@jdevelop.com>.
On Tue, Sep 20, 2005 at 04:46:37PM +0300, Eugeny N Dzhurinsky wrote:
> Could somebody please advice:
> I created spider for the WEB using the HTTPClient
> In this parser I always tried to use
> new URI(URIString, false)
> but for some reason the URLs looking like
> http://www.vlissingen.nl/upload/207353_340_1127124319551-voetbal7_%28LM%29.jpg
> are reported as broken URLs
> What do I do in the wrong way.

Here is the test case:

import java.io.IOException;

import junit.framework.Assert;
import junit.framework.TestCase;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.URI;
import org.apache.commons.httpclient.cookie.CookiePolicy;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.params.HttpClientParams;
import org.apache.commons.httpclient.params.HttpMethodParams;

public class HTTPClientTest extends TestCase {

    HttpClient client;

    HttpMethod method;

    public static void main(String[] args) {
        TestCase test = new HTTPClientTest() {
            public void runTest() {
                testResultcode();
            };
        };
    }

    protected void setUp() throws Exception {
        client = new HttpClient();
        URI uri = new URI(
                "http://www.vlissingen.nl/upload/207353_340_1127124319551-voetbal7_%28LM%29.jpg",
                false);
        method = new GetMethod(uri.getEscapedURI());
        HttpMethodParams params = method.getParams();
        params.setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
        params.setParameter(HttpClientParams.USER_AGENT, "Mozilla/4.0"
                + "(compatible; MSIE 6.0; Windows NT 5.1;)");
        method.setFollowRedirects(true);
    }

    public void testResultcode() {
        try {
            client.executeMethod(method);
            Assert.assertEquals(HttpStatus.SC_OK, method.getStatusCode());
        } catch (HttpException e) {
            e.printStackTrace(System.out);
        } catch (IOException e) {
            e.printStackTrace(System.out);
        }
    }

}

-- 
Eugene N Dzhurinsky

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org