简体   繁体   中英

cUrl command C++ code replacement

我有这个cUrl命令,需要在Linux下的C ++程序中执行,我正在使用Qt方式并包括libcUrl,我需要知道与该cUrl命令相当的确切方法调用:

curl -d 'grant_type=client_credentials&client_id=mdme2323&client_secret=asdaeqwedsa24124ewesiou&scope=http://api.microsofttranslator.com' https://datamarket.accesscontrol.windows.net/v2/OAuth2-13 | python -m json.tool

What about execute the command in a new process?

QString cmd("curl -d 'grant_type=client_credentials&client_id=mdme2323&client_secret=asdaeqwedsa24124ewesiou&scope=http://api.microsofttranslator.com' https://datamarket.accesscontrol.windows.net/v2/OAuth2-13 | python -m json.tool");
QProcess::execute(cmd);

Here is how I fixed it:

QProcess* proc = new QProcess();
QString cmd( "/bin/sh" );
QStringList args;
args << "-c" << "curl -d 'grant_type=client_credentials&client_id=islam123&client_secret=23ewsed323we2ewesiou&scope=http://api.microsofttranslator.com' https://datamarket.accesscontrol.windows.net/v2/OAuth2-13";
proc->execute(cmd, args);
data = proc->readAll();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM