webwrite
write content to the url and ouputs response of web service.
Attention: Valid only with Altair Communication Extension.
Syntax
response = webwrite(url,data)
response = webwrite(url,data,options)
Inputs
- url
- URL address
- data
- Data to be written to URL address
- options
- web options. output of weboptions.
Outputs
- response
- return response from url.
Examples
Post string data to url
data = '{"fields":["key","summary"],"jql":"key=VSM-10009"}';
res = webwrite('https://httpbin.org/post',data)
res = {
"args": {},
"data": "",
"files": {},
"form": {
"{\"fields\":[\"key\",\"summary\"],\"jql\":\"key": "VSM-10009\"}"
},
res = "headers": {
"Accept": "*/*",
"Content-Length": "86",
"Content-Type": "application/x-www-form-urlencoded",
"Host": "httpbin.org",
"X-Amzn-Trace-Id": "Root=1-658204f4-3c6926f7069e885c6b2968a8"
},
res = "json": null,
"origin": "174.74.87.47",
"url": "https://httpbin.org/post"
}
Post struct data to url
data_strct = struct('fields',{'key','summary'},'jql','key=VSM-10009');
res = webwrite('https://httpbin.org/post',data_strct)
res = {
"args": {},
"data": "",
"files": {},
"form": {
"fields": "key",
"jql": "key=VSM-10009"
},
"headers": {
"Accept": "*/*",
"Content-Length": "30",
"Content-Type": "application/x-www-form-urlencoded",
"Host": "httpbin.org",
"X-Amzn-Trace-Id": "Root=1-65820570-43efeacc69508a3809316e38"
},
"json": null,
"origin": "174.74.87.47",
"url": "https://httpbin.org/post"
}
Post data to url by defining web options, content type as json under headerfields
headers = struct('Content-Type','application/json');
payload = jsonencode(struct('name','Apple AirPods', 'data',struct('color','white', 'generation','3rd', 'price',135)));
url = 'https://api.restful-api.dev/objects'
opts = weboptions('HeaderFields',headers);
out = webwrite(url,payload,opts);
out = {"id":"ff8081818c01d7ae018c3bbc7fe138a7","name":"Apple AirPods","createdAt":"2023-12-05T20:47:38.465+00:00","data":{"color":"white","generation":"3rd","price":135}}