Webrequest and POST

Discussion in 'ASP .Net' started by Jay, Nov 28, 2005.

  1. Jay

    Jay Guest

    am trying to call a webservice from C# client.
    I am having trouble sending a POST via webrequest.

    This is the URL: http://T9946ISP0001:8080/PrintMgr/ProcessRequest.jsp

    Here is the method : createSession

    The params are :param1=1024

    Following is the code snippet - I am not sure how I specify the URL , the
    method name and its params..

    ----------------------------------------------------------------------------
    ------------------

    req.ContentLength = postData.Length;

    HttpWebRequest req = (HttpWebRequest)

    WebRequest.Create("http://T9946ISP0001:8080/PrintMgr/ProcessRequest.jsp");

    req.Method = "POST";


    ASCIIEncoding enc = new ASCIIEncoding();

    byte[] postData = enc.GetBytes("methodAlias=createSession&param1=1024");

    req.ContentLength = postData.Length;

    Stream reqStream = req.GetRequestStream();

    reqStream.Write(postData, 0, postData.Length);

    reqStream.Close();

    WebResponse resp = req.GetResponse();
     
    Jay, Nov 28, 2005
    #1
    1. Advertising

  2. Jay

    Joerg Jooss Guest

    Jay wrote:

    > am trying to call a webservice from C# client.
    > I am having trouble sending a POST via webrequest.
    >
    > This is the url: http://T9946ISP0001:8080/PrintMgr/ProcessRequest.jsp
    >
    > Here is the method : createSession
    >
    > The params are :param1=1024
    >
    > Following is the code snippet - I am not sure how I specify the URL ,
    > the method name and its params..
    >
    > ----------------------------------------------------------------------
    > ------ ------------------
    >
    > req.ContentLength = postData.Length;
    >
    > HttpWebRequest req = (HttpWebRequest)
    >
    > WebRequest.Create("http://T9946ISP0001:8080/PrintMgr/ProcessRequest.js
    > p");
    >
    > req.Method = "POST";
    >
    >
    > ASCIIEncoding enc = new ASCIIEncoding();
    >
    > byte[] postData =
    > enc.GetBytes("methodAlias=createSession&param1=1024");
    >
    > req.ContentLength = postData.Length;
    >
    > Stream reqStream = req.GetRequestStream();
    >
    > reqStream.Write(postData, 0, postData.Length);
    >
    > reqStream.Close();
    >
    > WebResponse resp = req.GetResponse();


    A Web Service deployed as JSP? That doesn't seem right... anyway,
    you're code is basically OK, except that you don't set a Content-Type
    and that you need to know if that Web Service can be called like that
    or if you need to use SOAP as protocol. In the latter case forget about
    manually implementing this functionality and use Visual Studio to build
    a Web Service client.

    Cheers,
    --
    http://www.joergjooss.de
    mailto:
     
    Joerg Jooss, Nov 28, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sujith Jagini

    problem with webRequest.method = post

    Sujith Jagini, Aug 16, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    1,491
    Natty Gur
    Aug 17, 2003
  2. John Saunders

    Re: problem with webRequest.method = post

    John Saunders, Aug 20, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    414
    John Saunders
    Aug 20, 2003
  3. Joerg Jooss
    Replies:
    0
    Views:
    1,129
    Joerg Jooss
    Apr 10, 2004
  4. guoqi zheng
    Replies:
    3
    Views:
    725
    Nathan Sokalski
    May 29, 2006
  5. Jay

    Webrequest and POST

    Jay, Nov 28, 2005, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    157
    Joerg Jooss
    Nov 28, 2005
Loading...

Share This Page