Communication between C# and PHP

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hello,
I am having some trouble with my code for PHP communication
The problem:
When I run this function several times in a row some times its rumble in line:

<div style="color:black; background-color:white
<pre>doc = XDocument.Load(reader);
receive = doc.ToString();
[/code]

<br/>
<br/>

The function:

<div style="color:black; background-color:white
<pre><span style="color:blue public <span style="color:blue static <span style="color:blue void Send(<span style="color:blue string command)
{
XDocument doc;
confCode();
<span style="color:blue if (command == <span style="color:#a31515 "")
<span style="color:blue return;
commandBuffer = command;

<span style="color:blue string receive = <span style="color:blue string.Empty;
WebRequest req = WebRequest.Create(Server.connectionAddress);
req.Method = <span style="color:#a31515 "POST";
req.ContentType = <span style="color:#a31515 "application/x-www-form-urlencoded";

<span style="color:blue string postData = Send_process(command);
<span style="color:green //checking for the right command
<span style="color:blue if (postData == <span style="color:#a31515 "FALSE")
<span style="color:blue return;

Console.WriteLine(postData);

<span style="color:blue byte[] byteArray = Encoding.UTF8.GetBytes(postData);
req.ContentLength = byteArray.Length;

Stream ds = req.GetRequestStream();
ds.Write(byteArray, 0, byteArray.Length);
ds.Close();


WebResponse wr = req.GetResponse();
ds = wr.GetResponseStream();
StreamReader reader = <span style="color:blue new StreamReader(ds);


doc = XDocument.Load(reader);
receive = doc.ToString();
}
[/code]

<br/>
Can someone help me out ?
The error:

<pre lang="x-c# System.Xml.XmlException: There are multiple root elements. Line 2, position 2.
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r)
at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r, LoadOptions o)
at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options)
at System.Xml.Linq.XDocument.Load(TextReader textReader, LoadOptions options)[/code]
<br/>
<br/>

I am searching whole day but without any result :?

PS:. The php is running well there is no problem in it !
<
https://plus.google.com/107037898992990075942<br/>
<br/>

View the full article
 
Back
Top