Skip to content

Cant hit localhost #45

@DayneD89

Description

@DayneD89

For some reason, I am unable to hit a localhost address. To replicate this I am hosting http://jsonplaceholder.typicode.com/ locally on port 3000 and I can confirm that accessing this url through a web browser brings up the same information as using the site. For this example I'll be using the path /todos/1/.

int type = 2;
string uhost = (type == 1) 
    ? "https://jsonplaceholder.typicode.com"
     : "http://localhost";

new RestAssured()
    .Given()
        .Name("Localhost Test")
        .Port((type == 1) ? 80 : 3000)
    .When()
        .Get(uhost+"/todos/1")
    .Then()
        .TestStatus("test a", x => x == 200)
        .Assert("test a")
    .WriteAssertions();

When type is 1 this runs as expected, however, when I change it to 2 (localhost) it gets back a HTML page and a 404 (Thus it fails to parse as Content-Type is html, but I set a custom parser to just print the _content to the console for this content-type).

Localhost does work if I change this to;

new RestAssured()
    .Given()
        .Name("Localhost Test")
        .Port((type == 1) ? 80 : 3000)
        .Host(uhost)
    .When() 
        .Get("/todos/1")
    .Then()
        .TestStatus("test a", x => x == 200)
        .Assert("test a")
    .WriteAssertions();```

However, needing a workaround isn't elegant.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions