Trying to make a PUT request using webwrite - "Unsupported Media Type"??
6 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(1 个)
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.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!