我正在尝试使用Ideone.com的SOAP API编译一些代码片段。为此,我必须在SOAP请求中发送源代码。以下是该SOAP请求的规范:
<message name="createSubmissionIn">
<part name="user" type="xsd:string"/>
<part name="pass" type="xsd:string"/>
<part name="sourceCode" type="xsd:string"/>
<part name="language" type="xsd:int"/>
<part name="input" type="xsd:string"/>
<part name="run" type="xsd:boolean"/>
<part name="private" type="xsd:boolean"/>
</message>
如上所述,sourceCode
应该是一个字符串,而代码是'text'。
以,例如以下代码:
#include <iostream>
using namespace std;
int main()
{
cout<<"Hello Ideone!";
return 0;
}
如果我encodeURIComponent
在发送请求之前在javascript客户端中(如其他地方所述),则生成的文本为:
%23include%20%0A%0Ausing%20namespace%20std%3B%0A%0Aint%20main()%0A%7B%0A%09cout%3C%3C%22Hello%20Ideone!%22%3B%0A%09return%200%3B%0A%7D
被推迟为无效代码(编译错误)。我确认了在服务器上收到的代码,并且代码没有在服务器端解码。
如果我将其作为单行发送,则编译错误仍然存在,因为您无法在#include
行中获得其余代码。
我也试过了CDATA的东西,但dint做了什么。
所以,请指导我解决这个问题。如何在SOAP请求中成功发送代码段。
P.S。为了防止我的客户端设计不好,我使用的是在线SOAP客户端: http://soapclient.com/soapclient?template=%2Fclientform.html&fn=soapform&SoapTemplate=%2FSoapResult.html&SoapWSDL=http%3A%2F%2Fideone.com%2Fapi%2F1%2Fservice.wsdl&_ArraySize=5
答案 0 :(得分:0)
今天,似乎他们的API可能会被打破。这里提供了一个演示python客户端。 http://ideone.com/files/python-test/ideone.py但是,它失败并出现身份验证错误。所以,为了尝试回答你的问题,我写了这两个迷你Perl程序。
<强>客户端强>
#!/usr/bin/perl -w
use SOAP::Lite;
my ($user, $pass, $source, $lang, $input, $run, $private);
$user = "FRED";
$pass = "PASS";
$lang=1;
$source = <<CODEDOC;
#include <iostream>
using namespace std;
int main()
{
cout<<"Hello Ideone!";
return 0;
}
CODEDOC
$input="INPUT";
$run=0;
$private=0;
print SOAP::Lite
-> proxy('http://localhost/cgi-bin/code_demo.pl')
-> uri('http://localhost/CodeDemo')
-> code($user, $pass, $source, $lang, $input, $run, private)
-> result;
Sever(CGI)
#!/usr/bin/perl -w
use SOAP::Transport::HTTP;
SOAP::Transport::HTTP::CGI
-> dispatch_to('CodeDemo')
-> handle;
package CodeDemo;
sub code{
my ($self, $user, $pass, $source, $lang, $input, $run, $private) = @_;
my $retval ;
$retval = sprintf("User:%s\nPass:%s\nSource:%s\nLang:%s\nInput:%s\nRun:%s\nPrivate:%s\n",
$user, $pass, $source, $lang, $input, $run, $private);
return $retval;
}
这似乎对我很好。
答案 1 :(得分:0)
没问题。这是一个经过工作和测试的PHP版本。我实际测试了这个并使用该服务上传了代码。我确实注意到即使我在创建帐户期间设置了API密码,也需要更新我的个人资料。
<?php
$client = new SoapClient('http://ideone.com/api/1/service.wsdl');
$user = "VALID_USER_NAME";
$pass = "VALID_PASSWORD";
$lang=1;
$source = <<<CODEDOC
#include <iostream>
using namespace std;
int main()
{
cout<<"Hello Ideone!";
return 0;
}
CODEDOC;
$input="INPUT";
$run=0;
$private=0;
print_r($client->createSubmission($user, $pass, $source, $lang, $input, $run, $private));
?>