Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. HTTPWebRequest sending right in POST method but manually inserting null

HTTPWebRequest sending right in POST method but manually inserting null

Scheduled Pinned Locked Moved ASP.NET
questionphpcomregexhelp
2 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sachin k Rajput
    wrote on last edited by
    #1

    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!

    F 1 Reply Last reply
    0
    • S Sachin k Rajput

      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!

      F Offline
      F Offline
      F ES Sitecore
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups