In my ASP.NET Core 3.1 Web API project, I am reading the request content using the following code:
string body = new StreamReader(Request.Body).ReadToEnd();
This needs to be done synchronously so I set already:
services.Configure<KestrelServerOptions>(options =>{options.AllowSynchronousIO = true;});
services.Configure<IISServerOptions>(options =>{options.AllowSynchronousIO = true;});
I can’t create model class as parameter of the method [FromBody], I need to read it as string.
This problem depends on my json body request (testing in postman). When i replace for example “custom_id”: “21312312” to “custom_id”: “” it stops working.
The issues I’m facing are:
- The application occasionally stops at the StreamReader line of code, depending on the request body.
- Even when the request body is successfully read into a string, it sometimes gets truncated.
This problem seems to depend on the specific JSON request body I’m using for testing in Postman. For instance, if I change “custom_id”: “21312312” to “custom_id”: “”, the application stops at this line of code.
Example json payload where application stops (at debug mode):
{"id":"WH-2WR32451HC0233532-67976317FL4543714","event_version":"1.0","create_time":"2021-04-02T10:38:40.000Z","resource_type":"sale","event_type":"PAYMENT.SALE.COMPLETED","summary":"Payment completed for $ 123.45 USD","resource":{"id":"8XF55052KT826122L","state":"completed","amount":{"total":"123.45","currency":"USD","details":{"subtotal":"120.00","tax":"3.45"}},"payment_mode":"INSTANT_TRANSFER","protection_eligibility":"ELIGIBLE","protection_eligibility_type":"ITEM_NOT_RECEIVED_ELIGIBLE,UNAUTHORIZED_PAYMENT_ELIGIBLE","transaction_fee":{"value":"3.00","currency":"USD"},"invoice_number":"48787589673","custom":"","parent_payment":"PAY-1PA12106FU478450MKRETS4A","create_time":"2021-04-02T10:38:33Z","update_time":"2021-04-02T10:38:40Z","links":[{"href":"https://api.paypal.com/v1/payments/sale/8XF55052KT826122L","rel":"self","method":"GET"},{"href":"https://api.paypal.com/v1/payments/sale/8XF55052KT826122L/refund","rel":"refund","method":"POST"},{"href":"https://api.paypal.com/v1/payments/payment/PAY-1PA12106FU478450MKRETS4A","rel":"parent_payment","method":"GET"}]},"links":[{"href":"https://api.paypal.com/v1/notifications/webhooks-events/WH-2WR32451HC0233532-67976317FL4543714","rel":"self","method":"GET"},{"href":"https://api.paypal.com/v1/notifications/webhooks-events/WH-2WR32451HC0233532-67976317FL4543714/resend","rel":"resend","method":"POST"}]}