0
私は次のようにREST Webサービスを呼び出すためにしようとしています:Perlの残りのWebサービスパラメータ
my $client = REST::Client->new();
$client->setHost("http://myhost.com");
$client->POST('/xx/yy/Submit',
$params,
{'Content-type' => 'application/json'}
);
my $response = $client->responseContent();
私はどのようにパラメータリストを作成していない、次のようにAPIの定義は次のとおりです。
{
"Credential": {
"Username": "String",
"Password": "String"
},
"DataCoding": "Default",
"Header": {
"From": "String",
"ValidityPeriod": 0
},
"Message": "String",
"To": ["String"]
}
私が試しました以下が、うまくいきませんでした:
my %params = (Credential => {
Username => $username,
Password => $password
},
DataCoding => 'Default',
Header => {
From => $from,
ValidityPeriod => 0
},
Message => "Test",
To => ['90535xxxx','90542xxxxx']
);
$client->POST('/v1/xml/syncreply/Submit',
encode_json(\%params),
{'Content-type' => 'application/json',
'Accept' => 'application/json'
}
);
それは次のエラーを与える:
<ErrorCode>SerializationException</ErrorCode>
Error: System.Runtime.Serialization.SerializationException: There was an error deserializing the object of type Barabut.Gw.Submit. The data at the root level is invalid. Line 1, position 1. ---&gt; System.Xml.XmlException: The data at the root level is invalid. Line 1, position 1.
ハッシュのハッシュを使用し、適切なモジュール([JSON :: PP](http://p3rl.org/JSON::PP)がコアにある)を介してJSONにシリアル化します。 – choroba
'To => ['90535xxxx']'であるべきですが、失敗の理由ではないようです。 – choroba
@choroba、私はそれを実現し、 'To'パラメータとして配列を送りました。私はエンコードされたjsonデータは正しいが、それでもエラーを返す –