#shimul_webhooks

1 messages ¡ Page 1 of 1 (latest)

wooden matrixBOT
#

👋 Welcome to your new thread!

⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1239489242330300459

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

manic rootBOT
sand zenith
#

A small correction: I am getting the HTTP Request body by using the Java Servlet API's HttpServletRequest.getReader() method. I've also shared the code I am using to get hold of the request body.

heady condor
#

Hi
In order to correctly verify the webhook signature, you don't need to parse or change the format of the request body. You need to use the rawbod

sand zenith
#

Yes, I know I need to use the raw request body. The example is given using the Spark framework. But I am using pure Java Servlet API, and I can't use any other framework. Can you help how to get the raw request body using the Servlet API?

#

Since I am pretty sure I am using the correct webhook secret and the signature header from Stripe is also fine, I doubt the problem must be with the request body.

#

I can share the signature header, webhook secret and the request body for the event that is being passed to the verification method if you need.

heady condor
#

In your loop, aren't you missing a sb.append('\r'); after sb.append(line)?

heady condor
sand zenith
sand zenith
heady condor
sand zenith
#

Thanks @heady condor , the issue is solved. Your solution to appending a newline actually solved my problem. Thanks a lot. Now I am actually using this code to get hold of the request body:

StringBuilder sb = new StringBuilder();
char[] charBuffer = new char[8192];
int bytesRead;
while ((bytesRead = reader.read(charBuffer)) != -1) {
sb.append(charBuffer, 0, bytesRead);
}
String reqBody = sb.toString();