weboptions adding additional header parameters/parameters to HTTP POST request

16 次查看(过去 30 天)
Hi,
I am trying to connect to an API where I need to pass the Authorization token. The authorization is part of the header of HTTP POST.
Authorization: abc230
Cache-Control: no-cache
Connection: keep-alive
Content-Length: 2
Content-Type: application/json
In Matlab, 'weboptions' function/object can have 'Username' and 'Password' as named fields. It also mentions 'KeyName' and 'KeyValue' as additional fields that can be passed.
I wanted to clarify if the following command will make things consistent with the API header requirement:
weboptions('RequestMethod','POST','ContentType', 'json','Timeout',60,'KeyName','Authorization','KeyValue','abc230')
This is my output
CharacterEncoding: 'auto'
UserAgent: 'MATLAB 8.5.0.197613 (R2015a)'
Timeout: 60
Username: ''
Password: ''
KeyName: 'Authorization'
KeyValue: 'abc230'
ContentType: 'json'
ContentReader: []
MediaType: 'application/x-www-form-urlencoded'
RequestMethod: 'post'
Thanks,
Vaibhav

回答(1 个)

Morrie Gasser
Morrie Gasser 2017-2-6
Prior to R2016b, KeyName and KeyValue let you add one custom header field to the request. In R2016b, weboptions now allows you to specify an arbitrary number of header fields using the 'HeaderFields' option.

类别

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