Serialize XmlDocument & send via HTTPWebRequest

后端 未结 3 1982
半阙折子戏
半阙折子戏 2021-01-14 21:29

I\'m trying to figure out how to properly serialize my XmlDocument and send it via a HTTPWebRequest object.

Here\'s what I have thus far:

Stream reques         


        
3条回答
  •  清歌不尽
    2021-01-14 22:06

    Works (somewhat)! Thanks, heres the code:

    Stream requestStream;
    Stream responseStream;
    WebResponse response;
    StreamReader sr;
    byte[] postData;
    string postString;
    postString = xmlAccess.OuterXml + xmlRequest.OuterXml;
    postData = Encoding.UTF8.GetBytes(postString);
    
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://wwwcie.ups.com/ups.app/xml/Track");
    request.Method = "POST";
    request.ContentType = "application/x-www-form-urlencoded";
    request.ContentLength = postData.Length;
    requestStream = request.GetRequestStream();
    
    requestStream.Write(postData, 0, postData.Length);
    requestStream.Close();
    
    response = request.GetResponse();
    responseStream = response.GetResponseStream();
    sr = new StreamReader(responseStream);
    
    return sr.ReadToEnd();
    

    It still doesnt return proper XML though:

     
       <...
    

    Not sure why there's 2x

提交回复
热议问题