Click here to Skip to main content
15,892,965 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I use this code

[WebMethod]
public string GetResponsePOSTData()
{
string valueReturn = string.Empty;
try
{
//Our postvars
string dataToPost = "username=username&password=password";
byte[] buffer = Encoding.ASCII.GetBytes(dataToPost);
//Initialization, we use localhost, change if applicable
HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create("http://localhost:8081/testSubmit.php");

//Our method is post, otherwise the buffer (postvars) would be useless
WebReq.Method = "POST";

//We use form contentType, for the postvars.
//WebReq.ContentType = "application/x-www-form-urlencoded";
WebReq.ContentType = "text/xml";
//The length of the buffer (postvars) is used as contentlength.
WebReq.ContentLength = buffer.Length;

//We open a stream for writing the postvars
Stream PostData = WebReq.GetRequestStream();
//Now we write, and afterwards, we close. Closing is always important!
PostData.Write(buffer, 0, buffer.Length);
PostData.Close();

//Get the response handle, we have no true response yet!
HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();

//Now, we read the response (the string), and output it.
Stream Answer = WebResp.GetResponseStream();
StreamReader _Answer = new StreamReader(Answer);
valueReturn = _Answer.ReadToEnd().ToString();
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}

return valueReturn;
}

but it returns :

This XML file does not appear to have any style information associated with it. The document tree is shown below.

it must add arguments [WebMethod] or make a configuration in the Web.Config file ???
Posted
Updated 10-Jul-14 3:10am

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900