These are chat archives for gin-gonic/gin

26th
Feb 2019
sgon00
@sgon00
Feb 26 13:46
hi, I am getting crazy with CORS. I have spent a long time on this. I have followed this method to reply OPTIONS request, but why does my chrome still complain blocked by CORS policy: No 'Access-Control-Allow-Origin’ header? Please help me! Thank you very much
?
sgon00
@sgon00
Feb 26 13:54
@Depado not yet. Do I need to do anything in the client code too? Maybe something worng with my client code and I have to add some headers to the request. I don’t know. still googling now.
Depado
@Depado
Feb 26 13:55
No you don't, it's your browser that checks for CORS policy.
It first runs a "preflight" request (OPTIONS) to see if the CORS policy allows the request.
This lib actually handles this pretty well. CORS actually happens when your frontend tries to execute queries on another domain, and it's a browser protection
sgon00
@sgon00
Feb 26 13:58
@Depado I am reading this https://stackoverflow.com/questions/23915992/problems-with-dart-server-angulardart-and-cors The answer is talking something that I need to do in client. I don’t quite understand it. I will try to use the middleware you gave me first to see if it works. thanks a lot.
Depado
@Depado
Feb 26 13:59
You're welcome :)
sgon00
@sgon00
Feb 26 14:03
@Depado that works very well. Thank you very much. You save my life!
Depado
@Depado
Feb 26 14:04
Hehe :D
sgon00
@sgon00
Feb 26 14:04
🙏🙏
sgon00
@sgon00
Feb 26 14:53
Hi, when the request body is a json string, how to get the request body as a string? So far, I only know c.ShouldBindJSON(&object) to bind it. I tried to use c.GetRawData(), but it panics somehow.
sgon00
@sgon00
Feb 26 14:59
(1) I was just trying to debug the request body. I am wondering what other people do when they want to check what request body has. Thanks.
(2) One more question, I am sending a json request payload, it has something like {“number”:0}. This binding failed with the error message Error:Field validation for ’Number' failed on the 'required' tag. Isn’t possible to use zero as a value? Thanks.
Depado
@Depado
Feb 26 15:16
Use ioutil.ReadAll without trying to bind JSON