2017-02-13 140 views
0

我试图复制一个curl命令其在UNIX机器上正常工作:curl命令

curl -X POST --insecure <ENDPOINT> -H "Content-Type: application/json" -H "<OTHER HEADERS>" -d @<PATH TO JSON FILE>

什么Matlab的命令,我可以使用在Windows机器上复制这个命令?我竭力要找到一种方法来添加--insecure选项

非常感谢

+0

'系统'将在系统命令窗口中运行任何命令 –

回答

0

让我们用一个例子,我使用Emacs的resclient,但没有得到吓人对于

我的目标是运用MATLAB amke这一呼吁:

# 
# Request 
# 
:auth-token = abcd1234 
:number := (+ 1 2 3 4) 
:text := (concat "This is " ":num" "ber") 
# 
# Multiline variable referencing another variable 
# 
:common-headers = << 
Authentication: :auth-token 
User-Agent: MyApp/1.0 
Content-type: application/json 
# 
# ...and another one 
:common-body = << 
{ "number": :number, "text": ":text" } 
# 
# Now, use them both in request 
# 
POST http://httpbin.org/post?q=1 
:common-headers 

:common-body 

其结果是:

{ 
    "args": { 
    "q": "1" 
    }, 
    "data": "{ \"number\": 10, \"text\": \"This is 10\" }", 
    "files": null, 
    "form": null, 
    "headers": { 
    "Accept": "*/*", 
    "Accept-Charset": "utf-8;q=1, gb2312;q=0.5, iso-8859-1;q=0.5, big5;q=0.5, iso-2022-jp;q=0.5, shift_jis;q=0.5, euc-tw;q=0.5, euc-jp;q=0.5, euc-jis-2004;q=0.5, euc-kr;q=0.5, us-ascii;q=0.5, utf-7;q=0.5, hz-gb-2312;q=0.5, big5-hkscs;q=0.5, gbk;q=0.5, gb18030;q=0.5, iso-8859-5;q=0.5, koi8-r;q=0.5, koi8-u;q=0.5, cp866;q=0.5, koi8-t;q=0.5, windows-1251;q=0.5, cp855;q=0.5, iso-8859-2;q=0.5, iso-8859-3;q=0.5, iso-8859-4;q=0.5, iso-8859-9;q=0.5, iso-8859-10;q=0.5, iso-8859-13;q=0.5, iso-8859-14;q=0.5, iso-8859-15;q=0.5, windows-1250;q=0.5, windows-1252;q=0.5, windows-1254;q=0.5, windows-1257;q=0.5, cp775;q=0.5, cp850;q=0.5, cp852;q=0.5, cp857;q=0.5, cp858;q=0.5, cp860;q=0.5, cp861;q=0.5, cp863;q=0.5, cp865;q=0.5, cp437;q=0.5, macintosh;q=0.5, next;q=0.5, hp-roman8;q=0.5, adobe-standard-encoding;q=0.5, iso-8859-16;q=0.5, iso-8859-7;q=0.5, windows-1253;q=0.5, cp737;q=0.5, cp851;q=0.5, cp869;q=0.5, iso-8859-8;q=0.5, windows-1255;q=0.5, cp862;q=0.5, iso-2022-jp-2004;q=0.5, cp874;q=0.5, iso-8859-11;q=0.5, viscii;q=0.5, windows-1258;q=0.5, iso-8859-6;q=0.5, windows-1256;q=0.5, iso-2022-cn;q=0.5, iso-2022-cn-ext;q=0.5, iso-2022-jp-2;q=0.5, iso-2022-kr;q=0.5, utf-16le;q=0.5, utf-16be;q=0.5, utf-16;q=0.5, x-ctext;q=0.5", 
    "Authentication": "abcd1234", 
    "Content-Length": "38", 
    "Content-Type": "application/json", 
    "Extension": "Security/Digest Security/SSL", 
    "Host": "httpbin.org", 
    "Mime-Version": "1.0", 
    "User-Agent": "MyApp/1.0" 
    }, 
    "json": { 
    "number": 10, 
    "text": "This is 10" 
    }, 
    "origin": "46.222.44.201", 
    "url": "http://httpbin.org/post?q=1" 
} 
// POST http://httpbin.org/post?q=1 
// HTTP/1.1 200 OK 
// Server: nginx 
// Date: Mon, 13 Feb 2017 10:29:40 GMT 
// Content-Type: application/json 
// Content-Length: 1768 
// Connection: keep-alive 
// Access-Control-Allow-Origin: * 
// Access-Control-Allow-Credentials: true 
// Request duration: 0.613051s 

让我们把它转变为卷曲:

curl -i -H 'Content-type: application/json' -H 'User-Agent: MyApp/1.0' -H 'Authentication: abcd1234' -XPOST 'http://httpbin.org/post?q=1' -d '{ "number": 10, "text": "This is 10" }' 

,最后把它翻译MATLAB的,我建议你使用urlread2这是从MATLAB的MATLAB程序fileexchange你只注册,您可以下载中心它。它是由Jim Hokason,取得了最近的MATLAB版本(2016),您可以try this

与urlread2

所以从here

上述要求可能是这样的:

>> %% Create the headers 
>> hct = http_createHeader('Content-Type','application/json'); 
>> hua = http_createHeader('User-Agent','matlab'); 
>> ha = http_createHeader('Authentication','abcd1234'); 
>> %% method 
>> method = 'POST'; 

>> body = '{"number":10, "text: "this is 10"}'; 

>> x = urlread2('http://httpbin.org/post?q=', method, body, [hct hua ha]) 

x = 

{ 
    "args": { 
    "q": "" 
    }, 
    "data": "{\"number\":10, \"text: \"this is 10\"}", 
    "files": {}, 
    "form": {}, 
    "headers": { 
    "Accept": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2", 
    "Authentication": "abcd1234", 
    "Content-Length": "34", 
    "Content-Type": "application/json", 
    "Host": "httpbin.org", 
    "User-Agent": "matlab" 
    }, 
    "json": null, 
    "origin": "46.222.44.201", 
    "url": "http://httpbin.org/post?q=" 
} 

对于不安全的选项,我不要认为这个验证ssl certifiactes