HTTPWebRequest sending right in POST method but manually inserting null
-
Hi, I'm trying to POST values to a php service by HTTPWebRequest then It's returning true and inserting right values but when I'm doing it manually it is returning null. Here is the Code:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.abc.com/showmydata/installinfo.php");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
string postData = "IMNumber=353323065370373&IPAddress=132.168.5.7";
byte[] bytes = Encoding.UTF8.GetBytes(postData);
request.ContentLength = bytes.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(bytes, 0, bytes.Length);
WebResponse response = request.GetResponse();
Stream stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream);
var result = reader.ReadToEnd();
stream.Dispose();
reader.Dispose();It's working fine by this code but , when I'm doing it manually : http://www.abc.com/showmydata/installinfo.php?IMNumber=353323065370373&IPAddress=132.168.5.7 It is returning both IMNumber and IPAddress null. Please help me in this how manually is wrong and what is the pattern of HttpWebRequest that returning it correctly. Thanks!
-
Hi, I'm trying to POST values to a php service by HTTPWebRequest then It's returning true and inserting right values but when I'm doing it manually it is returning null. Here is the Code:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.abc.com/showmydata/installinfo.php");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
string postData = "IMNumber=353323065370373&IPAddress=132.168.5.7";
byte[] bytes = Encoding.UTF8.GetBytes(postData);
request.ContentLength = bytes.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(bytes, 0, bytes.Length);
WebResponse response = request.GetResponse();
Stream stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream);
var result = reader.ReadToEnd();
stream.Dispose();
reader.Dispose();It's working fine by this code but , when I'm doing it manually : http://www.abc.com/showmydata/installinfo.php?IMNumber=353323065370373&IPAddress=132.168.5.7 It is returning both IMNumber and IPAddress null. Please help me in this how manually is wrong and what is the pattern of HttpWebRequest that returning it correctly. Thanks!
When you do it manually you are sending a GET, not a POST. If the target service is coded to only work from POST then it thinks you have not sent it any parameters. To simulate a POST you'll need to use a tool like fiddler, or there are various add-ons for various browsers that will let you do this, things like "Postman" for Chrome.