Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Matlab中设置http post请求的主体_Matlab_Rest_Post - Fatal编程技术网

如何在Matlab中设置http post请求的主体

如何在Matlab中设置http post请求的主体,matlab,rest,post,Matlab,Rest,Post,我想用Matlab发布一个restful服务。我尝试过使用webread、webwrite和urlread,但我不知道如何设置消息体 我的主体是json,如下所示: {“Item1”:“string1”,“Item2”:“string2”}我发现我做错了什么。我把我的身体构造成字符串文字,而不是matlab结构。正确的方法: api = 'http://myurl.net'; url = [api, '/Login']; [un, pw] = GetAuthentication; input =

我想用Matlab发布一个restful服务。我尝试过使用webread、webwrite和urlread,但我不知道如何设置消息体

我的主体是json,如下所示:


{“Item1”:“string1”,“Item2”:“string2”}

我发现我做错了什么。我把我的身体构造成字符串文字,而不是matlab结构。正确的方法:

api = 'http://myurl.net';
url = [api, '/Login'];
[un, pw] = GetAuthentication;
input = struct('Username',un,'Password',pw);
opts = weboptions('MediaType','application/json');
userInfo = webwrite(url, input, opts);

您正在尝试发布到该服务,因此您是否尝试了
webwrite
而不是
webread
?是的,我尝试过。很抱歉没有列出来。我还在weboptions对象中使用post尝试了webread。您是否尝试过按照文档第一段中的概述分别传递项目名称和值?是的,它返回一个500错误:/I我正在使用postman登录,它工作正常。但是,因为我使用的是vpn,所以我无法使用fiddler拦截我的web流量并对其进行分析。