2014-10-27 99 views
0

我想使用soap服務,它接收xml數據,併發送xml數據。 在控制檯應用程序我得到性反應使用此代碼:HttpRequest憑證

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("SaopUrl"); 

      request.Credentials = new NetworkCredential("login", "password"); 
      request.Method = "POST"; 
      request.PreAuthenticate = true; 
      string postData = @"query_xml=<MY-XML>"; 

      byte[] byteArray = Encoding.UTF8.GetBytes (postData); 
      request.ContentType = "application/x-www-form-urlencoded"; 
      request.ContentLength = byteArray.Length; 
      Stream dataStream = request.GetRequestStream(); 
      dataStream.Write (byteArray, 0, byteArray.Length); 
      dataStream.Close(); 
      WebResponse response = request.GetResponse(); 
      Console.WriteLine (((HttpWebResponse)response).StatusDescription); 
      dataStream = response.GetResponseStream(); 
      StreamReader reader = new StreamReader (dataStream); 
      string responseFromServer = reader.ReadToEnd(); 
      Console.WriteLine(responseFromServer); 
      reader.Close(); 
      dataStream.Close(); 
      response.Close(); 

但在回答我收到不批准。 如果我使用HTML表單操作是這樣的:

<form action="soapUrl" method="post" style="padding:0px"> 
<table cellpadding="5px" cellspacing="0px"> 
    <tr> 
     <td> 
      <textarea name="query_xml" name="query_xml" cols="100" rows="30"></textarea>   
     </td> 
    </tr> 
    <tr> 
     <td align="center"> 
      <input type="submit" value="Send" /> 
     </td> 
    </tr> 
</table> 
</form> 

我得到良好的反響。如何使用HttpRequest在C#中執行此操作?

回答