Effacer les filtres
Effacer les filtres

weboptions adding additional header parameters/parameters to HTTP POST request

16 vues (au cours des 30 derniers jours)
vaibhav
vaibhav le 1 Juil 2015
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

Réponses (1)

Morrie Gasser
Morrie Gasser le 6 Fév 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.

Catégories

En savoir plus sur Call Web Services from MATLAB Using HTTP dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by