필터 지우기
필터 지우기

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

조회 수: 17 (최근 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 CenterFile Exchange에서 Web Services에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by