将curl转换为Matlab/Webwrite [英] Translating curl into Matlab/Webwrite

查看:206
本文介绍了将curl转换为Matlab/Webwrite的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用curl将以下curl命令发送到Web服务器,并使用POST进行Webwrite.我的问题是,我总是收到错误的请求"答案,因此我的语法一定是错误的.有人知道这个curl命令如何以正确的方式使用Webwrite在Matlab中发送正文吗?

I have the following curl command I need to sent to a web server using Matlab and webwrite using POST. My problem is that I always get a "Bad request" answer so my syntax must be wrong somehow. Does anybody have an idea how this curl command, sending the body could look like in Matlab using webwrite in a correct way ?

body=$(cat << EOF
{
  "order": {
    "units": "100",
    "instrument": "EUR_USD",
    "timeInForce": "FOK",
    "type": "MARKET",
    "positionFill": "DEFAULT"
  }
}
EOF
)

curl \
  -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <AUTHENTICATION TOKEN>" \
  -d "$body" \
  "https://api-fxtrade.oanda.com/v3/accounts/<ACCOUNT>/orders"

推荐答案

正文的正确格式如下:

body = struct('units',100,'instrument','EUR_USD','timeInForce','FOK',...
   'type','MARKET','positionFill','DEFAULT');

对于您需要的HTTP 标头,您可以使用网络选项"rel =" nofollow noreferrer> webwrite .

As for the HTTP headers that you require you can specify them with weboptions when using webwrite.

附加标头的语法:

options = weboptions('KeyName','Name','KeyValue','Value')

其中 Name Value 分别是标题的名称及其值. 您必须在weboptions中添加所需的标头.

Where Name and Value are the name of the header and its value respectively. You must add the headers that you require in weboptions.

对于您提供的代码,正确的语法如下:

For the code you provided, the correct syntax would be as follows:

options = weboptions('MediaType','application/json',...
'KeyName','Authorization: Bearer','KeyValue','Token');

然后您可以在感兴趣的URL上执行POST请求.

You can then perform the POST request at the URL of interest.

response = webwrite(url,body,options);

这篇关于将curl转换为Matlab/Webwrite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆