0

I want to communicate with tally server, I am sending this code for http request and response from tally server is:

ü ¦€.Yk{ê1±<á";…òò÷ÁŽ›¾±àBÃZe´z ú÷¨éß"íè„™ýÊwº3€åµª§µ¡5ÒÀýVÿX5¥­OIdY©çÝ/Ì$ŠË¼Zœdí¼Ã%Ö Ýø®‘}}á–À†™;r?(Û„“?xS#%öDaÊʆ$“dÊ©V´ë†g2_FªÖ.·£Ð½†/ò     

my code is given below

public void Test()
{
    string xmlMessage = "<ENVELOPE><HEADER> <ID>TPGETCOMPANIES</ID> <SOURCE>EA</SOURCE> <TYPE>DATA</TYPE> <CONTENT-TYPE>text/xml;charset=utf-8</CONTENT-TYPE> <SESSIONID>1408730012927569997</SESSIONID> <TALLYREQUEST>Import</TALLYREQUEST> <TARGET>TNS</TARGET> </HEADER> <BODY> <DESC> <STATICVARIABLES> <SVINCLUDE>Connected</SVINCLUDE> </STATICVARIABLES></DESC></BODY></ENVELOPE>"; 

    string url = "https://dev1.tallyenterprise.com";
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

    byte[] requestInFormOfBytes = System.Text.Encoding.ASCII.GetBytes(xmlMessage);
    request.Method ="POST";

    request.ContentType = "text/xml;charset=utf-8";
    request.ContentLength = requestInFormOfBytes.Length;
    Stream requestStream = request.GetRequestStream();
    requestStream.Write(requestInFormOfBytes, 0, requestInFormOfBytes.Length);
    requestStream.Close();

    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    StreamReader respStream = new StreamReader(response.GetResponseStream(), System.Text.Encoding.Default);
    string receivedResponse = respStream.ReadToEnd();
    Label1.Text = receivedResponse;
    response.Close();
    respStream.Close();
 }

If anyone work on this please suggest me..

har07
  • 88,338
  • 12
  • 84
  • 137
Mahendra Suthar
  • 237
  • 1
  • 2
  • 6
  • I suspect that content is gzipped or deflated. Try adding this just after you create the WebRequest: `request.AutomaticDecompression = DecompressionMethods.GZip;` – rene Aug 30 '14 at 14:11
  • possible duplicate of [Http request to tally server](http://stackoverflow.com/questions/26055784/http-request-to-tally-server) – Grice Oct 02 '14 at 14:13

1 Answers1

0

Try this

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();
}
TejpalBh
  • 427
  • 4
  • 13