Webrequest and POST

  • Thread starter Thread starter Jay
  • Start date Start date
J

Jay

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 said:
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,
 
Back
Top