开发者

Is it possible to make http requests with MATLAB?

Is it possible to make http requests with MATLAB?

I am specifically interested in the way to make a request and store the response as a new varia开发者_如何转开发ble.


Try starting with the functions urlread and web.


urlread will make an HTTP request to any URL and return the results as a char array.

For example:

>> s = urlread('http://www.mathworks.com');
>> whos s
  Name      Size               Bytes  Class    Attributes

  s         1x23346            46692  char               

Depending on exactly what you're looking to extract as a variable, you may have to further post-process the result using functions like regexp and str2double.


You can use matlab.net.http

header = [matlab.net.http.field.AcceptField(matlab.net.http.MediaType('application/json'))...
    matlab.net.http.field.ContentTypeField('text/plain');];
body = jsonencode(data);
request = matlab.net.http.RequestMessage(matlab.net.http.RequestMethod.POST,...
    header,...
    body);
response = send(request, self.address);
result = response.Body.Data;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜