필터 지우기
필터 지우기

weboptions adding additional header parameters/parameters to HTTP POST request

조회 수: 16 (최근 30일)
vaibhav
vaibhav 2015년 7월 1일
답변: Morrie Gasser 2017년 2월 6일
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