Trying to make a PUT request using webwrite - "Unsupported Media Type"??

6 ビュー (過去 30 日間)
Mark Lepage
Mark Lepage 2019 年 11 月 25 日
編集済み: Tim Williams 2022 年 7 月 28 日
Hello everyone,
So I am working withe Yahoo Fantasy API, and can freely make API GET requests, using the following weboptions:
headerFields = {'Authorization', ['Bearer ', access_token]};
options = weboptions('HeaderFields', headerFields, 'ContentType','xmldom','Timeout',30);
reponse = webread(url,options);
However, now I am looking to make a PUT request, and now I am using webwrite:
headerFields = {'Authorization', ['Bearer ', access_token]};
options = weboptions('RequestMethod','post','HeaderFields', headerFields, 'ContentType','xmldom','Timeout',30);
reponse = webwrite(url,data,options);
Where data represents my formatted xml body.
I keep getting the following error
The server returned the status 415 with message
"Unsupported Media Type" in response to the request to URL
https://fantasysports.yahooapis.com/fantasy/v2/team/nhl.l.XXXXX.t.X/roster;
I am new to this and really don't understand why I am getting this error. From the API documentation, it is saying the Content-Type should be application/xml, but I can't set that in MATLAB.
Anyone have any idea what I can do to fix this?

回答 (1 件)

Tim Williams
Tim Williams 2022 年 7 月 28 日
編集済み: Tim Williams 2022 年 7 月 28 日
I recently experienced the 415 error when attempting to use webwrite. Internet search brought me to this post. I was able to overcome it thanks to documentation at https://www.mathworks.com/help/matlab/ref/webwrite.html. In my case, the expected MediaType was "application/json". The documentation instructs you how to change MediaType as needed via the 'options'. After changing the MediaType, I was able to successfully write data to the REST API.

カテゴリ

Help Center および File ExchangeCall 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