weboptions adding additional header parameters/parameters to HTTP POST request
17 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Morrie Gasser
on 6 Feb 2017
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.
0 Comments
More Answers (0)
See Also
Categories
Find more on Web Services in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!