本文介绍了Http请求计数服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我正在使用的代码和我正在接收的输出。

This is the code that I am using and output I am receiving.

输出:

.Yk{ 1 < ; B Ze z 脙 w 3 嵪 5 V X5 OIdY / $ Z d % }} ; r?(ۄ ?xS#% Da $ dʩ V g2_F . /

在此行中:
流requestStream = request.GetRequestStream() ;

requestStream.Length requestStream.Position 抛出类型的异常System.NotSupportedException

public void Test() {
     string xmlMessage =  "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +

         "<HEADER>" +
             "<ID>Ram</ID>" +
             "<SOURCE></SOURCE>" +
             "<TARGET></TARGET>" +
             "<CONTENT-TYPE>text/xml;charset=utf-8</CONTENT-TYPE>" +
          "</HEADER>" +

          "<ENVELOPE>" +

               "<VERSION></VERSION>" +
               "<REQVERSION></REQVERSION>" +
               "<TALLYREQUEST></TALLYREQUEST>" +
               "<TYPE></TYPE>" +
               "<ID></ID>" +
               "<CONTENT-TYPE>/xml;charset=utf-8</CONTENT-TYPE>" +
               "<SESSIONID></SESSIONID>" +
               "<TOKEN></TOKEN>" +

               "<BODY>" +
                   "<DESC>" +
                   "<STATICVARIABLES>" +
                   "<SVINCLUDE></SVINCLUDE>" +
                   "</STATICVARIABLES>" +
                   "</DESC>" +
               "</BODY>" +
          "</ENVELOPE>";

      //Sending the request to Tally test URL address
        string url = "www.xxxxxxx.com";

        //create a request
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        request.KeepAlive = false;
        request.ProtocolVersion = HttpVersion.Version10;
        request.Method = "POST";
        string postData = xmlMessage;
        // turn our request string into a byte stream
        byte[] byteArray = Encoding.UTF8.GetBytes(postData);
        //byte[] requestInFormOfBytes = new UTF8Encoding(false).GetBytes(xmlMessage);

        request.ContentType = "text/xml;charset=utf-8";

        request.ContentLength = byteArray.Length;

        Stream requestStream = request.GetRequestStream();

        requestStream.Write(byteArray, 0, byteArray.Length);

        requestStream.Close();

        HttpWebResponse response = (HttpWebResponse)request.GetResponse();

        StreamReader respStream = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8);

       string receivedResponse = respStream.ReadToEnd();
       Label2.Text = receivedResponse;

       respStream.Close();
       response.Close();
    }


推荐答案

试试这个

public void Test() {

string xmlMessage =  "<ENVELOPE>
<HEADER>
    <VERSION>1</VERSION>
    <REQVERSION>1</REQVERSION>
    <TALLYREQUEST>EXPORT</TALLYREQUEST>
    <TYPE>DATA</TYPE>
    <ID>TPGETCOMPANIES</ID>
    <SESSIONID>" .$session. "</SESSIONID>
    <TOKEN>" .$token. "</TOKEN>
</HEADER>
<BODY>
<DESC>
<STATICVARIABLES>
    <SVINCLUDE>CONNECTED</SVINCLUDE>
</STATICVARIABLES>
</DESC>
</BODY>
</ENVELOPE>";

//Sending the request to Tally test URL address
string url = "www.xxxxxxx.com";

//create a request
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.KeepAlive = false;
request.ProtocolVersion = HttpVersion.Version10;
request.Method = "POST";
string postData = xmlMessage;

byte[] byteArray = Encoding.UTF8.GetBytes(postData);

request.ContentType = "text/xml;charset=utf-8";
request.ContentLength = byteArray.Length;

request.Headers.Add("ID", "TPGETCOMPANIES");
request.Headers.Add("SOURCE", "EA");
request.Headers.Add("TARGET", "TNS");
request.Headers.Add("CONTENT-TYPE", "text/xml;charset=utf-8");

Stream requestStream = request.GetRequestStream();
requestStream.Write(byteArray, 0, byteArray.Length);
requestStream.Close();

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader respStream = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8);

string receivedResponse = respStream.ReadToEnd();
Label2.Text = receivedResponse;

respStream.Close();
response.Close();
}

这篇关于Http请求计数服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-30 13:23