I'm using this code in android to get a response from a server using POST:
public string PostDataRequest(string url,string postData){
WebResponse response = null;
Stream dataStream = null;
StreamReader reader = null;
try {
HttpWebRequest httpWReq =
(HttpWebRequest)WebRequest.Create(url);
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] data = encoding.GetBytes(postData);
httpWReq.Method = "POST";
httpWReq .KeepAlive = true ;
httpWReq.ContentType = "application/x-www-form-urlencoded";
httpWReq.ContentLength = data.Length;
using (Stream newStream = httpWReq.GetRequestStream())
{
newStream.Write(data, 0, data.Length);
}
response = httpWReq.GetResponse();
// Get the stream containing content returned by the server.
dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
// Clean up the streams.
reader.Close();
dataStream.Close();
response.Close();
//return the content.
return responseFromServer;
} catch (Exception ex) {
}
I encounter "Expectation failed" exception when I run the app , but when I use hotspotshield on my phone it works fine!when I use the url in a browser it works fine even without hotspotshield. why is that and how can I fix this issue. most of forums suggest this line of code : System.Net.ServicePointManager.Expect100Continue = false; but it didn't work. please advise. Thank you