#shimul_webhooks
1 messages ¡ Page 1 of 1 (latest)
đ 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.
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.
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
This quickstart is a good starting point:
https://docs.stripe.com/webhooks/quickstart?lang=java
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.
In your loop, aren't you missing a sb.append('\r'); after sb.append(line)?
Can you use these variables using the java sample I shared with you? just to confirm that you are using the correct values
I can't understand what you mean. I have only taken the verification code from the example you shared with me.
Let me try adding a new line as you said, and come back to you...
In order to confirm that you are using the correct value of the webhook secret and the stripe api key, I suggest you to run the Java sample as it is in your local laptop and trigger some test events and see if it works. The first step is to verify that the values you are trying to use are correct.
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();