GET request with body

조회 수: 16 (최근 30일)
Austin O'Connell
Austin O'Connell . 2020년 10월 13일
댓글: Austin O'Connell . 2020년 10월 19일
Is it possible to send a GET request that includes a body in the RequestMessage?
I've tried the following code
request = RequestMessage;
request.Body = MessageBody;
request.Body.Data = struct('Name1', 'value1', 'Name2', 'value2');
request.Method = 'get';
uri = URI('');
[response, completedReq, history] = send(request, uri);
Every time I try this, I get the following response:
Warning: Body unexpected in message using request method GET.
Despite this just being a warning, my web request seems to never even send. Suppressing warnings by doing warnings('off') didn't make a difference.
Additionally, I have tried using webread and webwrite instead of send, but have not had any luck there as well.
Any ideas on how to get this working?

채택된 답변

Abhisek Pradhan
Abhisek Pradhan 2020년 10월 18일
As per my knowledge a request message containing a Body property normally uses a method such as 'PUT' or 'POST. But this is not something which is enforced. Try using POST or PUT and see if it works.
  댓글 수: 1
Austin O'Connell
Austin O'Connell 2020년 10월 19일
POST and PUT both work as expected.
My confusion was the sentence from the documentation here which states, "Normally, a 'GET' request does not contain data, but the method sends the Body regardless of the RequestMethod." I was under the assumption that we would still be able to send a GET request with a body.
Luckily in my case I have control over the API, so I'll update my API to use a POST instead of GET. Thanks for the help.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)


Help CenterFile Exchange에서 Call Web Services from MATLAB Using HTTP에 대해 자세히 알아보기


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by