0

エラーが返され、リクエストのエンコード方法について受け取った API マニュアルに従っています。以下は私の要求です..

string url = "[My url to send request to]";

string xmlrequest = "<serv_request><head><securityContext><account>[account]</account><key>[my account key]</key></securityContext></head><body><username>[my user name]</username></body></serv_request>";

NameValueCollection nvc = new NameValueCollection();
nvc.Add("xml", Server.UrlEncode(xmlrequest));


WebClient client = new WebClient();

byte[] byteresponse = client.UploadValues(url, nvc);

string xmlresponse = client.Encoding.GetString(byteresponse);

エラーで応答が返ってきます。ドキュメントのトップ レベルでは無効です。

編集..私に提供されたAPIマニュアルからの指示を追加..

string url = " http://[domain_name]/_gateway/api/[filename].asp"; 

// formulate the XML request here 

string xmlrequest = "<serv_request>...</serv_request>";  

NameValueCollection nvc = new NameValueCollection(); 
nvc.Add("xml", Server.UrlEncode(xmlrequest)); 

WebClient client = new WebClient(); 
byte[] byteresponse = client.UploadValues(url, nvc); 

string xmlresponse = client.Encoding.GetString(byteresponse); 
4

2 に答える 2

0

サーバーが適切な xml で応答していないようです。空の文字列または整形式の XML ではないテキストを返している可能性があります。

送信している xml をキャプチャしてみて、soapUI などのツールを使用してリクエストを送信し、そのレスポンスを確認してください。

また、コードの最後の行の代わりにこれを試してみてください:

文字列 xmlresponse = System.Text.Encoding.UTF8.GetString(byteresponse);

于 2013-11-22T21:08:00.173 に答える