Eugene Shmorgun Eugene Shmorgun - 1 year ago 105
Javascript Question

What is difference between POST-request of Vert.x and JavaScript?

I have vert.x application. In my verticle I have such route to perform post-request:"/api/1").handler(routingContext -> {
HttpServerResponse response = routingContext.response();
.putHeader("content-type", "text/html")
.end("Response from api");

OK, I want to test this request.

To do this I created unit-test:

public void testApi1(TestContext context) {
Async async = context.async();
HttpClient client = vertx.createHttpClient();
HttpClientRequest request =, "localhost", "api/1", response -> {

System.out.println("Some callback " + response.statusCode());

String body = "{'username':'www','password':'www'}";
request.putHeader("content-length", "1000");
request.putHeader("content-type", "application/x-www-form-urlencoded");

But when I try to execute this test I always get 404-error. In order to define the reason of this I used Postman (REST-client). It uses the follow request:

POST /api/1 HTTP/1.1
Host: localhost:8080
Cache-Control: no-cache
Postman-Token: 6065383d-8f51-405c-08fd-9cc824a22f92
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW

And this request return 404 too.

Very strange.

So I decided to create simple post-request from JavaScript - I used extremely simple code form JQuery:


And it returns me correct string, which I expect.

Who can explain me difference between these three issues.

Answer Source

In your HttpClientRequest request =, "localhost", "api/1", response -> { ...

You missed a "/" in the beginning, it should be:

HttpClientRequest request =, "localhost", "/api/1", response -> { ...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download