проблемы с выдачей POST в службу xml REST - PullRequest
1 голос
/ 25 января 2012

У меня есть следующий код C #, который я использую для POST в службу REST, работающую на ZEND php.Это код, который я использую для публикации

        string[] results = null;

        System.Net.WebRequest req = System.Net.WebRequest.Create(url);

        //set the method and content type
        req.ContentType = "application/xml";
        req.Method = "POST";

        //set the data
        byte[] bytes = System.Text.Encoding.Unicode.GetBytes(requestXML);
        req.ContentLength = bytes.Length;
        System.IO.Stream os = req.GetRequestStream();
        os.Write(bytes, 0, bytes.Length); //Push it out there
        os.Close();
        System.Net.WebResponse resp = req.GetResponse();

        if (resp == null) return null;

        System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
        string result = sr.ReadToEnd().Trim();

        return (results);

, это XML-файл

     <?xml version=\"1.0\"?> 
    <Root> <request> <APIClientID>4</APIClientID> <Version>0</Version>
    <APIPassword>A564942C8BF7999A42F564B6EC52AEEF0F03D7DC</APIPassword> <Function>TransAPIStats</Function>
  <Params> <Client>testClient</Client> 
    <Page>0</Page> <Application>hrblock-cb</Application>
    <Function>ecb</Function> 
    </Params>
     </request> 
    </Root> 

Однако он говорит, что я

<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<root><Status0>Error</Status0>
<Description0>Your POST data was empty. You need to submit an XML or JSON string 
with the proper parameters.</Description0></root>\n

1 Ответ

0 голосов
/ 25 января 2012

Может быть, вы можете попробовать RestSharp - https://github.com/restsharp/RestSharp

var client = new RestClient();
client.BaseUrl = url;
// client.Authenticator = new HttpBasicAuthenticator("username", "password");

var request = new RestRequest();
request.Resource = requestXML; // e.g. C:\Temp.xml

RestResponse response = client.Execute(request);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...