dependency
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.5.0</version>
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
Main.java
package org.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
@SpringBootApplication
public class Main {
public static void main(String[] args) {
SpringApplication.run(Main.class, args);
}
}
@Controller
@RequestMapping("/api")
class RequestController {
@PostMapping(path="/echo",
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public ResponseEntity<String> processFormPostBodyAndParams(
@RequestParam Map<String, String> body) {
return new ResponseEntity<>("Body param map: " + body, HttpStatus.OK);
}
}
application.yml
server:
port: 8088
http2:
enabled: true
when use http1.1 it work
when use http2 it not work
Comment From: surajbh123
@luelueking which JDK you are using ? Its working fine with jdk 17 that we use
Comment From: luelueking
oracle jdk 17.0.11
Comment From: surajbh123
@luelueking
const http2 = require('http2');
const querystring = require('querystring');
const client = http2.connect('http://localhost:8088');
const data = querystring.stringify({ key1: 'value1', key2: 'value2' });
const req = client.request({
':method': 'POST',
':path': '/api/echo',
'content-type': 'application/x-www-form-urlencoded',
'content-length': Buffer.byteLength(data)
});
req.setEncoding('utf8');
req.write(data);
let response = '';
req.on('data', (chunk) => { response += chunk; });
req.on('end', () => {
console.log('Response:', response);
client.close();
});
req.end();
This is working i have tried
Comment From: luelueking
it works on get params but not post params
Comment From: luelueking
I think is my test tool's problem. thx